Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increment challenge score when a whitelisted product is ordered & paid
Browse files Browse the repository at this point in the history
ithiame committed Jun 15, 2023
1 parent ea42f0f commit 16f5084
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib/server/orders.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,20 @@ export async function onOrderPaid(order: Order, session: ClientSession) {
productId: { $in: order.items.map((item) => item.product._id) }
})
.toArray();

const challenges = await collections.challenges.find({}).toArray();
for (const challenge of challenges) {
await collections.challenges.updateOne(
{ _id: challenge._id },
{
$set: {
progress: {
amount: challenge.progress.amount + order.totalPrice.amount,
currency: 'SAT'
}
}
}
);
}
for (const subscription of order.items.filter((item) => item.product.type === 'subscription')) {
const existingSubscription = subscriptions.find(
(sub) => sub.productId === subscription.product._id

0 comments on commit 16f5084

Please sign in to comment.