Skip to content

Commit

Permalink
Increment challenge score when a whitelisted product is ordered & paid
Browse files Browse the repository at this point in the history
  • Loading branch information
ithiame committed Jun 16, 2023
1 parent 3989b45 commit 0b36845
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/server/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { toSatoshis } from '$lib/utils/toSatoshis';
import { currentWallet, getNewAddress, orderAddressLabel } from './bitcoin';
import { lndCreateInvoice } from './lightning';
import { ORIGIN } from '$env/static/private';
import { sum } from '$lib/utils/sum';

async function generateOrderNumber(): Promise<number> {
const res = await collections.runtimeConfig.findOneAndUpdate(
Expand Down Expand Up @@ -40,7 +41,7 @@ export async function onOrderPaid(order: Order, session: ClientSession) {
endsAt: { $gt: new Date() }
})
.toArray();
let numberOfProducts = sum(order.items.map(item => item.quantity));
let numberOfProducts = sum(order.items.map((item) => item.quantity));
for (const challenge of challenges) {
await collections.challenges.updateOne(
{ _id: challenge._id },
Expand All @@ -49,7 +50,7 @@ export async function onOrderPaid(order: Order, session: ClientSession) {
progress:
challenge.mode === 'moneyAmount'
? toSatoshis(order.totalPrice.amount, order.totalPrice.currency)
: sumProduct
: numberOfProducts
}
},
{ session }
Expand Down

0 comments on commit 0b36845

Please sign in to comment.