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

Jobs should be fetched and scheduled based upon the selected Shop(#2r65b1c) #228

Merged
merged 16 commits into from
Sep 1, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/components/BatchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default defineComponent({
computed: {
...mapGetters({
getJob: 'job/getJob',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
userProfile: "user/getUserProfile"
}),
Expand Down
2 changes: 1 addition & 1 deletion src/components/JobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default defineComponent({
pinnedJobs: 'user/getPinnedJobs',
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
currentJob: 'job/getCurrentJob',
}),
Expand Down
23 changes: 17 additions & 6 deletions src/store/modules/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { hasError, showToast } from '@/utils'
import { JobService } from '@/services/JobService'
import { translate } from '@/i18n'
import { DateTime } from 'luxon';
import store from '@/store'

const actions: ActionTree<JobState, RootState> = {

Expand Down Expand Up @@ -185,9 +186,14 @@ const actions: ActionTree<JobState, RootState> = {
const params = {
"inputFields": {
"statusId": "SERVICE_PENDING",
"systemJobEnumId_op": "not-empty"
"systemJobEnumId_op": "not-empty",
"shopId_fld0_value": store.state.user.currentShopifyConfig?.shopId,
"shopId_fld0_grp": "1",
"shopId_fld0_op": "equals",
"shopId_fld1_grp": "2",
"shopId_fld1_op": "empty",
} as any,
"fieldList": [ "systemJobEnumId", "runTime", "tempExprId", "parentJobId", "serviceName", "jobId", "jobName", "currentRetryCount", "statusId", "productStoreId", "runtimeDataId", "description" ],
"fieldList": [ "systemJobEnumId", "runTime", "tempExprId", "parentJobId", "serviceName", "jobId", "jobName", "currentRetryCount", "statusId", "productStoreId", "runtimeDataId", "shopId", "description" ],
"noConditionFind": "Y",
"viewSize": payload.viewSize,
"viewIndex": payload.viewIndex,
Expand Down Expand Up @@ -415,10 +421,15 @@ const actions: ActionTree<JobState, RootState> = {
'runAsUser': 'system', //default system, but empty in run now. TODO Need to remove this as we are using SERVICE_RUN_AS_SYSTEM, currently kept it for backward compatibility
'recurrenceTimeZone': this.state.user.current.userTimeZone
},
'shopifyConfigId': this.state.user.currentShopifyConfigId,
'statusId': "SERVICE_PENDING",
'systemJobEnumId': job.systemJobEnumId
} as any

if(job?.runtimeData?.shopifyConfigId) {
const shopifyConfig = this.state.user.currentShopifyConfig
payload['shopifyConfigId'] = shopifyConfig?.shopifyConfigId
payload['jobFields']['shopId'] = shopifyConfig?.shopId
}

// checking if the runtimeData has productStoreId, and if present then adding it on root level
job?.runtimeData?.productStoreId?.length >= 0 && (payload['productStoreId'] = this.state.user.currentEComStore.productStoreId)
Expand Down Expand Up @@ -524,13 +535,13 @@ const actions: ActionTree<JobState, RootState> = {
'systemJobEnumId': job.systemJobEnumId,
'tempExprId': job.jobStatus, // Need to remove this as we are passing frequency in SERVICE_TEMP_EXPR, currently kept it for backward compatibility
'parentJobId': job.parentJobId,
'recurrenceTimeZone': this.state.user.current.userTimeZone
'recurrenceTimeZone': this.state.user.current.userTimeZone,
'shopId': job.runtimeData?.shopifyConfigId && job.status === "SERVICE_PENDING" ? job.shopId : this.state.user.currentShopifyConfig.shopId,
},
'shopifyConfigId': job.status === "SERVICE_PENDING" ? job.runtimeData?.shopifyConfigId : this.state.user.currentShopifyConfigId,
'shopifyConfigId': job.runtimeData?.shopifyConfigId && job.status === "SERVICE_PENDING" ? job.runtimeData?.shopifyConfigId : this.state.user.currentShopifyConfig.shopifyConfigId,
'statusId': "SERVICE_PENDING",
'systemJobEnumId': job.systemJobEnumId
} as any

// checking if the runtimeData has productStoreId, and if present then adding it on root level
job?.runtimeData?.productStoreId?.length >= 0 && (payload['productStoreId'] = job.status === "SERVICE_PENDING" ? job.productStoreId : this.state.user.currentEComStore.productStoreId)
job?.priority && (payload['SERVICE_PRIORITY'] = job.priority.toString())
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default interface UserState {
currentEComStore: object;
instanceUrl: string;
shopifyConfigs: any,
currentShopifyConfigId: string,
currentShopifyConfig: any,
}
27 changes: 13 additions & 14 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,37 +167,36 @@ const actions: ActionTree<UserState, RootState> = {
"inputFields": {
"productStoreId": productStoreId,
},
"entityName": "ShopifyConfig",
"entityName": "ShopifyShopAndConfig",
"noConditionFind": "Y",
"fieldList": ["shopifyConfigId", "shopifyConfigName"]
"fieldList": ["shopifyConfigId", "shopifyConfigName", "shopId"]
}
try {
resp = await UserService.getShopifyConfig(payload);
if (resp.status === 200 && !hasError(resp) && resp.data?.docs) {
const shopifyConfigs = resp.data.docs;
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, shopifyConfigs);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, shopifyConfigs.length > 0 ? shopifyConfigs[0].shopifyConfigId : "");
if (resp.status === 200 && !hasError(resp) && resp.data?.docs?.length > 0) {
commit(types.USER_SHOPIFY_CONFIGS_UPDATED, resp.data.docs);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, resp.data.docs[0]);
} else {
console.error(resp);
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, "");
commit(types.USER_SHOPIFY_CONFIGS_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, {});
}
} catch (err) {
console.error(err);
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, "");
commit(types.USER_SHOPIFY_CONFIGS_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, {});
}
} else {
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, "");
commit(types.USER_SHOPIFY_CONFIGS_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, {});
}
},

/**
* update current shopify config id
*/
async setCurrentShopifyConfigId({ commit }, id) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, id);
async setCurrentShopifyConfig({ commit }, shopifyConfig) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, shopifyConfig);
},

async setEComStore({ commit }, payload) {
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const getters: GetterTree <UserState, RootState> = {
const baseUrl = process.env.VUE_APP_BASE_URL;
return baseUrl ? baseUrl : state.instanceUrl;
},
getCurrentShopifyConfigId (state) {
return state.currentShopifyConfigId;
getCurrentShopifyConfig (state) {
return state.currentShopifyConfig;
},
getShopifyConfigs (state) {
return state.shopifyConfigs;
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const userModule: Module<UserState, RootState> = {
current: null,
instanceUrl: '',
shopifyConfigs: [],
currentShopifyConfigId: "",
currentShopifyConfig: {},
currentEComStore: {
productStoreId: "",
storeName: "None"
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export const USER_TOKEN_CHANGED = SN_USER + '/TOKEN_CHANGED'
export const USER_END_SESSION = SN_USER + '/END_SESSION'
export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_SHOPIFY_CONFIG_LIST_UPDATED = SN_USER + '/SHOPIFY_CONFIG_LIST_UPDATED'
export const USER_SHOPIFY_CONFIGS_UPDATED = SN_USER + '/SHOPIFY_CONFIGS_UPDATED'
export const USER_CURRENT_SHOPIFY_CONFIG_UPDATED = SN_USER + '/SHOPIFY_CONFIG_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
6 changes: 3 additions & 3 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mutations: MutationTree <UserState> = {
[types.USER_END_SESSION] (state) {
state.token = ''
state.current = null
state.currentShopifyConfigId = ""
state.currentShopifyConfig = {}
state.currentEComStore = {
productStoreId: "",
storeName: "None"
Expand All @@ -23,9 +23,9 @@ const mutations: MutationTree <UserState> = {
state.instanceUrl = payload;
},
[types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED] (state, payload) {
state.currentShopifyConfigId = payload;
state.currentShopifyConfig = payload;
},
[types.USER_SHOPIFY_CONFIG_LIST_UPDATED] (state, payload) {
[types.USER_SHOPIFY_CONFIGS_UPDATED] (state, payload) {
state.shopifyConfigs = payload
},
[types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) {
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/webhook/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { translate } from '@/i18n'

const actions: ActionTree<WebhookState, RootState> = {
async fetchWebhooks({ commit }) {
await WebhookService.fetchShopifyWebhooks({ shopifyConfigId: this.state.user.currentShopifyConfigId }).then(resp => {
await WebhookService.fetchShopifyWebhooks({ shopifyConfigId: this.state.user.currentShopifyConfig.shopifyConfigId }).then(resp => {
if (resp.status == 200 && resp.data.webhooks?.length > 0 && !hasError(resp)) {
const webhooks = resp.data.webhooks;
const topics: any = {}
Expand Down Expand Up @@ -39,7 +39,7 @@ const actions: ActionTree<WebhookState, RootState> = {
let resp;

try {
resp = await WebhookService.subscribeWebhook({ shopifyConfigId: this.state.user.currentShopifyConfigId }, id)
resp = await WebhookService.subscribeWebhook({ shopifyConfigId: this.state.user.currentShopifyConfig.shopifyConfigId }, id)

if (resp.status == 200 && !hasError(resp)) {
showToast(translate('Webhook subscribed successfully'))
Expand Down
4 changes: 2 additions & 2 deletions src/views/InitialLoad.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getCachedWebhook: 'webhook/getCachedWebhook'
}),
Expand Down Expand Up @@ -207,7 +207,7 @@ export default defineComponent({
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfigId })
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfig.shopifyConfigId })
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/views/Inventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr'
}),
Expand Down
4 changes: 2 additions & 2 deletions src/views/Orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default defineComponent({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
orderBatchJobs: "job/getOrderBatchJobs",
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr',
getCachedWebhook: 'webhook/getCachedWebhook'
Expand Down Expand Up @@ -282,7 +282,7 @@ export default defineComponent({
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfigId })
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfig.shopifyConfigId })
}
},
async updateAutoCancelDays() {
Expand Down
2 changes: 1 addition & 1 deletion src/views/PreOrder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr'
}),
Expand Down
4 changes: 2 additions & 2 deletions src/views/Product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default defineComponent({
getJobStatus: 'job/getJobStatus',
getTemporalExpr: 'job/getTemporalExpr',
getJob: 'job/getJob',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
getCachedWebhook: 'webhook/getCachedWebhook'
}),
newProductsWebhook(): boolean {
Expand Down Expand Up @@ -142,7 +142,7 @@ export default defineComponent({
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfigId })
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfig.shopifyConfigId })
}
},
async viewJobConfiguration(id: string, title: string, status: string) {
Expand Down
7 changes: 4 additions & 3 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ion-item>
<ion-icon :icon="globeOutline" slot="start" />
<ion-label>{{ $t("Shopify Config") }}</ion-label>
<ion-select interface="popover" :value="currentShopifyConfigId" @ionChange="setShopifyConfig($event)">
<ion-select interface="popover" :value="currentShopifyConfig?.shopifyConfigId" @ionChange="setShopifyConfig($event)">
<ion-select-option v-for="shopifyConfig in shopifyConfigs" :key="shopifyConfig.shopifyConfigId" :value="shopifyConfig.shopifyConfigId" >{{ shopifyConfig.shopifyConfigName }}</ion-select-option>
</ion-select>
</ion-item>
Expand Down Expand Up @@ -82,7 +82,7 @@ export default defineComponent({
currentEComStore: 'user/getCurrentEComStore',
instanceUrl: 'user/getInstanceUrl',
shopifyConfigs: 'user/getShopifyConfigs',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId'
currentShopifyConfig: 'user/getCurrentShopifyConfig'
})
},
methods: {
Expand All @@ -94,7 +94,8 @@ export default defineComponent({
}
},
setShopifyConfig(event: any){
this.store.dispatch('user/setCurrentShopifyConfigId', event.detail.value);
const shopifyConfig = this.shopifyConfigs.find((shopifyConfig: any) => shopifyConfig.shopifyConfigId === event.detail.value)
this.store.dispatch('user/setCurrentShopifyConfig', shopifyConfig);
},
async changeTimeZone() {
const timeZoneModal = await modalController.create({
Expand Down