diff --git a/src/routes/api/[slug]/+server.js b/src/routes/api/[slug]/+server.js index d172f416d9a3388d5ec5cb3fd8eef66147f5b0b2..2aea31c697627371788975ddf118289d6b4e4010 100644 --- a/src/routes/api/[slug]/+server.js +++ b/src/routes/api/[slug]/+server.js @@ -5,6 +5,8 @@ import { buyArticles, transferMoney, useVoucher } from "../transactions"; import { getUserById } from "../users"; import { Codes } from "$lib/customcodes"; import { AllOrNothingRateLimiter, SlidingWindowRateLimiter } from "../../../lib/ratelimit"; +import { sendNotification } from "$lib/server/notifications/handler"; +import { NotificationType } from "$lib/notifications/notificationTypes"; function isValidCart(cart, articles, voucherCart, vouchers, priceModifier){ @@ -43,6 +45,9 @@ export async function POST(event) { const items = [...data.items, ...data.vouchers.map(voucher => ({...voucher, code: Codes.Voucher}))]; if(user.perms & Flags.CANT_GO_NEGATIVE && items.reduce((acc, item) => acc + item.price + item.premium, 0) > user.balance) return new Response(JSON.stringify({message: "Not enough balance"}), {headers: {'content-type': 'application/json', 'status': 400}}); const res = await buyArticles(user.id, user.card, items, data.vouchers, !!(user.perms & Flags.NO_BALANCE)); + const total = items.reduce((acc, item) => acc + item.price + item.premium, 0); + // no need to await + sendNotification(user, NotificationType.BUY, {items: items.map(item=>Object.assign({}, item, {name: articles[item.code]?.name})), total, balanceBefore: user.balance, balanceAfter: user.balance - total}); return new Response(JSON.stringify(res), {headers: {'content-type': 'application/json', 'status': 200}}); }catch(e){ console.error(e);