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

Commit

Permalink
poscBranches refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Oct 11, 2023
1 parent fcc41d7 commit cff8e06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
34 changes: 30 additions & 4 deletions packages/plugin-pos-api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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: []
});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions packages/ui-settings/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ const ImageWrapper = styled.div`
export {
MarkdownWrapper,
FlexItem,
ItemCount,
FlexBetween,
ImageWrapper,
ActionButtons,
ExpandWrapper,
Expand Down

0 comments on commit cff8e06

Please sign in to comment.