Skip to content

Commit

Permalink
Merge pull request #456 from hotwax/shopId-support
Browse files Browse the repository at this point in the history
Added: support to pass shopId to runtime data
  • Loading branch information
adityasharma7 authored Apr 25, 2023
2 parents 5b37012 + 37f9e50 commit 362aeb3
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/store/modules/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,12 @@ const actions: ActionTree<JobState, RootState> = {
'systemJobEnumId': job.systemJobEnumId
} as any

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

job?.runtimeData?.shopifyConfigId && (payload['shopifyConfigId'] = shopifyConfig?.shopifyConfigId);
job?.runtimeData?.shopId && (payload['shopId'] = shopifyConfig?.shopId);
payload['jobFields']['shopId'] = shopifyConfig?.shopId;
}

// checking if the runtimeData has productStoreId, and if present then adding it on root level
Expand Down Expand Up @@ -626,9 +628,7 @@ const actions: ActionTree<JobState, RootState> = {
'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,
'shopId': job.runtimeData?.shopifyConfigId && job.status === "SERVICE_PENDING" ? job.shopId : this.state.user.currentShopifyConfig.shopId,
},
'shopifyConfigId': job.runtimeData?.shopifyConfigId && job.status === "SERVICE_PENDING" ? job.runtimeData?.shopifyConfigId : this.state.user.currentShopifyConfig.shopifyConfigId,
'statusId': "SERVICE_PENDING",
'systemJobEnumId': job.systemJobEnumId
} as any
Expand All @@ -637,6 +637,16 @@ const actions: ActionTree<JobState, RootState> = {
job?.priority && (payload['SERVICE_PRIORITY'] = job.priority.toString())
job?.sinceId && (payload['sinceId'] = job.sinceId)

// ShopifyConfig and ShopifyShop should be set based upon runtime data
// If existing job is run now, copy as is else set the current shop of user
if (job?.runtimeData?.shopifyConfigId || job?.runtimeData?.shopId) {
const shopifyConfig = this.state.user.currentShopifyConfig

job?.runtimeData?.shopifyConfigId && (payload['shopifyConfigId'] = job.status === "SERVICE_PENDING" ? job.runtimeData?.shopifyConfigId : shopifyConfig?.shopifyConfigId);
job?.runtimeData?.shopId && (payload['shopId'] = job.status === "SERVICE_PENDING" ? job.runtimeData?.shopId : shopifyConfig?.shopId);
payload['jobFields']['shopId'] = job.status === "SERVICE_PENDING" ? job.shopId : shopifyConfig?.shopId;
}

// assigning '' (empty string) to all the runtimeData properties whose value is "null"
job.runtimeData && Object.keys(job.runtimeData).map((key: any) => {
if (job.runtimeData[key] === 'null' ) job.runtimeData[key] = ''
Expand Down Expand Up @@ -804,13 +814,14 @@ const actions: ActionTree<JobState, RootState> = {
} as any


if (job?.runtimeData?.shopifyConfigId) {
if (job?.runtimeData?.shopifyConfigId || job?.runtimeData?.shopId) {
const shopifyConfig = this.state.user.shopifyConfigs.find((config: any) => {
return config.shopId === shopId;
})

params['shopifyConfigId'] = shopifyConfig.shopifyConfigId;
params['jobFields']['shopId'] = shopId;
job?.runtimeData?.shopifyConfigId && (params['shopifyConfigId'] = shopifyConfig.shopifyConfigId);
job?.runtimeData?.shopId && (params['shopId'] = shopifyConfig.shopId);
params['jobFields']['shopId'] = shopifyConfig.shopId;
}

// checking if the runtimeData has productStoreId, and if present then adding it on root level
Expand Down

0 comments on commit 362aeb3

Please sign in to comment.