diff --git a/packages/plugin-syncerkhet-api/src/afterMutations.ts b/packages/plugin-syncerkhet-api/src/afterMutations.ts index 0d11f8ca6c..fb8a627c84 100644 --- a/packages/plugin-syncerkhet-api/src/afterMutations.ts +++ b/packages/plugin-syncerkhet-api/src/afterMutations.ts @@ -131,14 +131,9 @@ export const afterMutationHandlers = async (subdomain, params) => { } // create sale - console.log( - Object.keys(saleConfigs), - destinationStageId, - 'ddddddddddddd' - ); if (Object.keys(saleConfigs).includes(destinationStageId)) { const brandRules = saleConfigs[destinationStageId].brandRules || {}; - console.log(brandRules, 'kkkkkkkkkkkkkkkkk'); + const brandIds = Object.keys(brandRules).filter(b => Object.keys(mainConfigs).includes(b) ); @@ -147,10 +142,18 @@ export const afterMutationHandlers = async (subdomain, params) => { for (const brandId of brandIds) { configs[brandId] = { ...mainConfigs[brandId], - ...brandRules[brandId] + ...brandRules[brandId], + hasPayment: saleConfigs[destinationStageId].hasPayment }; } - const postDatas = (await getPostData(subdomain, configs, deal)) as any; + + const postDatas = (await getPostData( + subdomain, + models, + user, + configs, + deal + )) as any; for (const data of postDatas) { const { syncLog, postData } = data; diff --git a/packages/plugin-syncerkhet-api/src/graphql/resolvers/mutations/checkSynced.ts b/packages/plugin-syncerkhet-api/src/graphql/resolvers/mutations/checkSynced.ts index 801f2c3868..dfd287e8f2 100644 --- a/packages/plugin-syncerkhet-api/src/graphql/resolvers/mutations/checkSynced.ts +++ b/packages/plugin-syncerkhet-api/src/graphql/resolvers/mutations/checkSynced.ts @@ -94,7 +94,14 @@ const checkSyncedMutations = { ...configs[syncedStageId], ...mainConfig }; - const postData = await getPostData(subdomain, config, deal, dateType); + const postData = await getPostData( + subdomain, + models, + user, + config, + deal, + dateType + ); const response = await sendRPCMessage( models, diff --git a/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts b/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts index defd0ca12a..173dfc1955 100644 --- a/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts +++ b/packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts @@ -3,6 +3,7 @@ import { sendCoreMessage, sendProductsMessage } from '../messageBroker'; +import { getSyncLogDoc } from './utils'; export const validConfigMsg = async config => { if (!config.url) { @@ -11,10 +12,19 @@ export const validConfigMsg = async config => { return ''; }; -export const getPostData = async (subdomain, configs, deal, dateType = '') => { +export const getPostData = async ( + subdomain, + models, + user, + configs, + deal, + dateType = '' +) => { let billType = 1; let customerCode = ''; + const syncLogDoc = getSyncLogDoc({ type: 'cards:deal', user, object: deal }); + const companyIds = await sendCoreMessage({ subdomain, action: 'conformities.savedConformity', @@ -306,12 +316,17 @@ export const getPostData = async (subdomain, configs, deal, dateType = '') => { } ]; + const syncLog = await models.SyncLogs.syncLogsAdd(syncLogDoc); + postDatas.push({ - userEmail: config.userEmail, - token: config.apiToken, - apiKey: config.apiKey, - apiSecret: config.apiSecret, - orderInfos: JSON.stringify(orderInfos) + syncLog, + postData: { + userEmail: config.userEmail, + token: config.apiToken, + apiKey: config.apiKey, + apiSecret: config.apiSecret, + orderInfos: JSON.stringify(orderInfos) + } }); } diff --git a/packages/plugin-syncerkhet-api/src/utils/utils.ts b/packages/plugin-syncerkhet-api/src/utils/utils.ts index f44c413b12..777f91c485 100644 --- a/packages/plugin-syncerkhet-api/src/utils/utils.ts +++ b/packages/plugin-syncerkhet-api/src/utils/utils.ts @@ -7,12 +7,13 @@ export const getSyncLogDoc = (params: { type: string; user: IUserDocument; object: any; + brandId?: string; }) => { - const { type, user } = params; + const { type, user, brandId } = params; return { type: '', - brandId: '', + brandId, contentType: type, contentId: params.object._id, createdAt: new Date(),