Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
send many erkhet sale
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Oct 31, 2023
1 parent ee39000 commit 13ffb48
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
19 changes: 11 additions & 8 deletions packages/plugin-syncerkhet-api/src/afterMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 21 additions & 6 deletions packages/plugin-syncerkhet-api/src/utils/ebarimtData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
sendCoreMessage,
sendProductsMessage
} from '../messageBroker';
import { getSyncLogDoc } from './utils';

export const validConfigMsg = async config => {
if (!config.url) {
Expand All @@ -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',
Expand Down Expand Up @@ -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)
}
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-syncerkhet-api/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 13ffb48

Please sign in to comment.