Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support for moqui login and logic to run service on releasing order / items (#293) #294

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 70 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@casl/ability": "^6.0.0",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.2.6",
"@hotwax/dxp-components": "1.13.0",
"@hotwax/oms-api": "1.14.0",
"@hotwax/dxp-components": "1.15.2",
"@hotwax/oms-api": "1.15.0",
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
"@ionic/vue-router": "^7.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"Size": "Size",
"Sizes": "Sizes",
"sku selected": "sku selected",
"Some of the configuration of the app is missing.": "Some of the configuration of the app is missing.",
"Some listing data not available": "Some listing data not available",
"Something went wrong": "Something went wrong",
"Something went wrong while login. Please contact administrator.": "Something went wrong while login. Please contact administrator.",
Expand Down
133 changes: 133 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ const login = async (username: string, password: string): Promise <any> => {
});
}

const moquiLogin = async (omsRedirectionUrl: string, token: string): Promise <any> => {
const baseURL = omsRedirectionUrl.startsWith('http') ? omsRedirectionUrl.includes('/rest/s1/order-routing') ? omsRedirectionUrl : `${omsRedirectionUrl}/rest/s1/order-routing/` : `https://${omsRedirectionUrl}.hotwax.io/rest/s1/order-routing/`;
let api_key = ""

try {
const resp = await client({
url: "login",
method: "post",
baseURL,
params: {
token
},
headers: {
"Content-Type": "application/json"
}
}) as any;

if(!hasError(resp) && (resp.data.api_key || resp.data.token)) {
api_key = resp.data.api_key || resp.data.token
} else {
throw "Sorry, login failed. Please try again";
}
} catch(err) {
return Promise.resolve("");
}
return Promise.resolve(api_key)
}

const setUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/setUserPreference",
Expand Down Expand Up @@ -189,11 +217,116 @@ const getUserProfile = async (token: any): Promise<any> => {
}
}

const runNow = async (): Promise<any> => {
const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo'];
if(!omsRedirectionInfo.url || !omsRedirectionInfo.token) {
console.error("Maarg instance is not setup for this account.");
return;
}

const url = omsRedirectionInfo.url
const baseURL = url.startsWith('http') ? url.includes('/rest/s1/order-routing') ? url : `${url}/rest/s1/order-routing/` : `https://${url}.hotwax.io/rest/s1/order-routing/`;
let resp = {} as any, payload = {};
let routingGroupId = "";

try {
resp = await client({
url: "checkOmsConnection",
method: "GET",
baseURL,
headers: {
"api_key": omsRedirectionInfo.token,
"Content-Type": "application/json"
}
});

if(hasError(resp)) {
throw resp.data;
}

payload = {
"inputFields": {
"settingTypeEnumId": "RUN_GROUP_ID"
},
"filterByDate": 'Y',
"entityName": "ProductStoreSetting",
"fieldList": ["settingValue", "fromDate"],
"viewSize": 1
}

resp = await api({
url: "performFind",
method: "post",
data: payload
});

if(!hasError(resp) && resp.data.docs[0].settingValue) {
routingGroupId = resp.data.docs[0].settingValue
} else {
throw resp.data;
}

let job;
resp = await client({
url: `groups/${routingGroupId}/schedule`,
method: "GET",
baseURL,
headers: {
"api_key": omsRedirectionInfo.token,
"Content-Type": "application/json"
}
})

if(!hasError(resp)) {
job = resp.data.schedule
} else {
throw resp.data;
}

if(!job.jobName) {
resp = await client({
url: `groups/${routingGroupId}/schedule`,
method: "POST",
data: {
routingGroupId,
paused: "Y", // passing Y as we just need to configure the scheduler and do not need to schedule it in active state
},
baseURL,
headers: {
"api_key": omsRedirectionInfo.token,
"Content-Type": "application/json"
}
});
if(hasError(resp)) {
throw resp.data;
}
}

resp = await client({
url: `groups/${routingGroupId}/runNow`,
method: "POST",
baseURL,
headers: {
"api_key": omsRedirectionInfo.token,
"Content-Type": "application/json"
}
});

if(hasError(resp)) {
throw resp.data;
}
} catch(error: any) {
console.error("Failed to schedule routing.", error)
}
}

export const UserService = {
getEComStores,
getPreferredStore,
getUserProfile,
getUserPermissions,
login,
moquiLogin,
runNow,
setUserPreference,
}
4 changes: 4 additions & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export default interface UserState {
pwaState: any;
instanceUrl: string;
currentEComStore: object;
omsRedirectionInfo: {
url: string;
token: string;
}
}
Loading
Loading