Skip to content

Commit

Permalink
Improved: logic to run job on releasing preorders (hotwax#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Aug 6, 2024
1 parent 89626f4 commit 21f083e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
69 changes: 69 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,81 @@ const getUserProfile = async (token: any): Promise<any> => {
}
}

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

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 isOmsConnectionExist = false, resp = {} as any;
let routingGroupId = "";

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

if(!hasError(resp)) {
isOmsConnectionExist = true
} else {
throw resp.data;
}

const 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)) {
routingGroupId = resp.data.docs[0].settingValue
} else {
throw resp.data;
}

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

if(hasError(resp)) {
throw resp.data;
}
} catch(error: any) {
console.error(error)
}
}

export const UserService = {
getEComStores,
getPreferredStore,
getUserProfile,
getUserPermissions,
login,
moquiLogin,
runNow,
setUserPreference,
}
2 changes: 2 additions & 0 deletions src/views/order-popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { defineComponent } from "vue";
import WarehouseModal from "@/views/warehouse-modal.vue";
import { useStore } from "@/store";
import PromiseDateModal from "@/views/promise-date-modal.vue";
import { UserService } from '@/services/UserService'
export default defineComponent({
name: "OrderPopover",
Expand Down Expand Up @@ -63,6 +64,7 @@ export default defineComponent({
handler: () => {
this.releaseItem(this.item).then(() => {
this.store.dispatch("order/removeItem", { item: this.item });
UserService.runNow();
})
},
}
Expand Down
2 changes: 2 additions & 0 deletions src/views/orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ import { showToast } from '@/utils'
import { Plugins } from '@capacitor/core';
import { DxpShopifyImg } from "@hotwax/dxp-components";
import emitter from "@/event-bus";
import { UserService } from '@/services/UserService'
const { Clipboard } = Plugins;
Expand Down Expand Up @@ -335,6 +336,7 @@ export default defineComponent({
}).then(() => {
// TODO Find a better place to call this
this.store.dispatch("order/removeItems", { items: selectedItems });
UserService.runNow();
}).finally(() => emitter.emit("dismissLoader"))
},
async cancelItems() {
Expand Down
4 changes: 3 additions & 1 deletion src/views/product-details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ import { DxpShopifyImg } from "@hotwax/dxp-components";
import { sizeIndex } from "@/apparel-sorter"
import { DateTime } from 'luxon';
import emitter from "@/event-bus";
import { UserService } from '@/services/UserService'
export default defineComponent({
name: "product-details",
Expand Down Expand Up @@ -452,8 +453,9 @@ export default defineComponent({
'Content-Type': 'multipart/form-data;'
},
data: formData
}).then(() => {
}).then(async () => {
this.store.dispatch("order/removeItems", { items: selectedItems });
UserService.runNow();
}).finally(() => emitter.emit("dismissLoader"))
},
async cancelItems() {
Expand Down

0 comments on commit 21f083e

Please sign in to comment.