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

Added: support to pass shopId to runtime data #456

Merged
merged 2 commits into from
Apr 25, 2023
Merged
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
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