From 21f083e16a9dd6b21b669cee617c8c83014a1a08 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 6 Aug 2024 15:03:32 +0530 Subject: [PATCH] Improved: logic to run job on releasing preorders (#293) --- src/services/UserService.ts | 69 +++++++++++++++++++++++++++++++++++ src/views/order-popover.vue | 2 + src/views/orders.vue | 2 + src/views/product-details.vue | 4 +- 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/services/UserService.ts b/src/services/UserService.ts index a9b235e35..106c40353 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -217,6 +217,74 @@ const getUserProfile = async (token: any): Promise => { } } +const runNow = async (): Promise => { + 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, @@ -224,5 +292,6 @@ export const UserService = { getUserPermissions, login, moquiLogin, + runNow, setUserPreference, } \ No newline at end of file diff --git a/src/views/order-popover.vue b/src/views/order-popover.vue index a17073d36..5dace47a9 100644 --- a/src/views/order-popover.vue +++ b/src/views/order-popover.vue @@ -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", @@ -63,6 +64,7 @@ export default defineComponent({ handler: () => { this.releaseItem(this.item).then(() => { this.store.dispatch("order/removeItem", { item: this.item }); + UserService.runNow(); }) }, } diff --git a/src/views/orders.vue b/src/views/orders.vue index f85d22973..ab0d9e78a 100644 --- a/src/views/orders.vue +++ b/src/views/orders.vue @@ -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; @@ -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() { diff --git a/src/views/product-details.vue b/src/views/product-details.vue index 5df0ab156..596cc1fb8 100644 --- a/src/views/product-details.vue +++ b/src/views/product-details.vue @@ -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", @@ -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() {