Skip to content

Commit

Permalink
fix: share status is checked when aggregating holdings
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Jan 3, 2025
1 parent 8d7074a commit 1cfc17e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 17 additions & 1 deletion apps/shares/src/db/shares.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 8 additions & 4 deletions apps/shares/src/shares.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 1cfc17e

Please sign in to comment.