From cff8e0662c65abb797c37bdc43445426f55ec48d Mon Sep 17 00:00:00 2001 From: munkhsaikhan Date: Wed, 11 Oct 2023 23:54:52 +0800 Subject: [PATCH] poscBranches refactor --- packages/plugin-pos-api/src/utils.ts | 34 ++++++++++++++++++++++++---- packages/ui-settings/src/styles.ts | 2 -- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/plugin-pos-api/src/utils.ts b/packages/plugin-pos-api/src/utils.ts index d7c658b33c..3619a2a81a 100644 --- a/packages/plugin-pos-api/src/utils.ts +++ b/packages/plugin-pos-api/src/utils.ts @@ -51,7 +51,9 @@ export const getBranchesUtil = async ( const allowsPos = await models.Pos.find({ isOnline: { $ne: true }, branchId: { $in: pos.allowBranchIds } - }).lean(); + }) + .sort({ onServer: -1, name: 1 }) + .lean(); let healthyBranchIds = [] as any; @@ -61,6 +63,10 @@ export const getBranchesUtil = async ( healthyBranchIds = allowsPos.map(p => p.branchId); } else { for (const allowPos of allowsPos) { + if (healthyBranchIds.includes(allowPos.branchId)) { + continue; + } + const response = await sendPosclientHealthCheck({ subdomain, pos: allowPos @@ -75,7 +81,23 @@ export const getBranchesUtil = async ( return await sendCoreMessage({ subdomain, action: 'branches.find', - data: { query: { _id: { $in: healthyBranchIds } } }, + data: { + query: { _id: { $in: healthyBranchIds } }, + fields: { + _id: 1, + title: 1, + address: 1, + radius: 1, + phoneNumber: 1, + email: 1, + coordinate: 1, + image: 1, + code: 1, + order: 1, + status: 1, + links: 1 + } + }, isRPC: true, defaultValue: [] }); @@ -341,7 +363,9 @@ export const statusToDone = async ({ const toPos = await models.Pos.findOne({ branchId: doneOrder.subBranchId, _id: { $ne: pos._id } - }).lean(); + }) + .sort({ onServer: -1, name: 1 }) + .lean(); // paid order info to offline pos if (toPos) { @@ -646,7 +670,9 @@ export const syncOrderFromClient = async ({ const toPos = await models.Pos.findOne({ branchId: newOrder.subBranchId, _id: { $ne: pos._id } - }).lean(); + }) + .sort({ onServer: -1, name: 1 }) + .lean(); // paid order info to offline pos if (toPos) { diff --git a/packages/ui-settings/src/styles.ts b/packages/ui-settings/src/styles.ts index d2ee744ede..765135b8f9 100644 --- a/packages/ui-settings/src/styles.ts +++ b/packages/ui-settings/src/styles.ts @@ -491,8 +491,6 @@ const ImageWrapper = styled.div` export { MarkdownWrapper, FlexItem, - ItemCount, - FlexBetween, ImageWrapper, ActionButtons, ExpandWrapper,