From 1cfc17e60583824c60828e210d9e0ce994b8d999 Mon Sep 17 00:00:00 2001 From: okjodom Date: Fri, 3 Jan 2025 10:47:22 +0300 Subject: [PATCH] fix: share status is checked when aggregating holdings --- apps/shares/src/db/shares.schema.ts | 18 +++++++++++++++++- apps/shares/src/shares.service.ts | 12 ++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/shares/src/db/shares.schema.ts b/apps/shares/src/db/shares.schema.ts index f74957e..d515cc5 100644 --- a/apps/shares/src/db/shares.schema.ts +++ b/apps/shares/src/db/shares.schema.ts @@ -52,12 +52,28 @@ export class SharesDocument extends AbstractDocument { export const SharesSchema = SchemaFactory.createForClass(SharesDocument); export function toSharesTx(share: SharesDocument): SharesTx { + let status: SharesTxStatus; + + if (share.status === undefined || share.status.toString() === '0') { + status = SharesTxStatus.PROPOSED; + } else if (share.status.toString() === '1') { + status = SharesTxStatus.PROCESSING; + } else if (share.status.toString() === '2') { + status = SharesTxStatus.APPROVED; + } else if (share.status.toString() === '3') { + status = SharesTxStatus.COMPLETE; + } else if (share.status.toString() === '4') { + status = SharesTxStatus.FAILED; + } else { + status = SharesTxStatus.UNRECOGNIZED; + } + return { id: share._id, userId: share.userId, offerId: share.offerId, quantity: share.quantity, - status: share.status, + status, transfer: share.transfer, createdAt: share.createdAt.toDateString(), updatedAt: share.updatedAt.toDateString(), diff --git a/apps/shares/src/shares.service.ts b/apps/shares/src/shares.service.ts index cb15480..3438233 100644 --- a/apps/shares/src/shares.service.ts +++ b/apps/shares/src/shares.service.ts @@ -154,10 +154,14 @@ export class SharesService { toSharesTx, ); - const shareHoldings = shares.reduce( - (sum, share) => sum + share.quantity, - 0, - ); + const shareHoldings = shares + .filter((share) => { + return ( + share.status === SharesTxStatus.COMPLETE || + share.status === SharesTxStatus.APPROVED + ); + }) + .reduce((sum, share) => sum + share.quantity, 0); const offers = await this.getSharesOffers();