Skip to content

Commit

Permalink
fix: included total amount on exlusive content (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 committed Feb 11, 2023
1 parent 90cbf4e commit 538dc4b
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/interceptors/pagination.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Friend,
FriendWithRelations,
PostWithRelations,
Transaction,
UnlockableContent,
User,
UserWithRelations,
Expand Down Expand Up @@ -379,15 +380,40 @@ export class PaginationInterceptor implements Provider<Interceptor> {
},
});
if (prices.length === 0) continue;
const updatedPrices = prices.map(price => {
return {
id: contentId,
price: price.amount,
decimal: price?.currency?.decimal ?? 0,
symbol: price?.currency?.symbol ?? 'UNKNOWN',
networId: price?.currency?.networkId ?? 'UNKNOWN',
};
});
const updatedPrices = await Promise.all(
prices.map(async price => {
const collection = (
this.transactionRepository.dataSource
.connector as AnyObject
).collection(Transaction.modelName);
const [total] = await collection
.aggregate([
{
$match: {
type: ReferenceType.UNLOCKABLECONTENT,
referenceId: contentId,
currencyId: price.currency?.id ?? '',
},
},
{
$group: {
_id: null,
amount: {$sum: '$amount'},
},
},
])
.get();

return {
id: contentId,
price: price.amount,
decimal: price?.currency?.decimal ?? 0,
symbol: price?.currency?.symbol ?? 'UNKNOWN',
networId: price?.currency?.networkId ?? 'UNKNOWN',
totalAmount: total?.amount ?? 0,
};
}),
);
updatedContents.push(...updatedPrices);
}

Expand Down

0 comments on commit 538dc4b

Please sign in to comment.