From 8c1a9fadabeaa2d88bdaf46af3124b72a60f4c04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aaron=20D=C3=B6tsch?= <aaron@fsmpi.rwth-aachen.de>
Date: Sat, 5 Aug 2023 19:21:58 +0200
Subject: [PATCH] Implement voucher use notifications

---
 src/routes/api/[slug]/+server.js | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/routes/api/[slug]/+server.js b/src/routes/api/[slug]/+server.js
index a7dcebb..c49ead2 100644
--- a/src/routes/api/[slug]/+server.js
+++ b/src/routes/api/[slug]/+server.js
@@ -89,6 +89,12 @@ export async function POST(event) {
 				}else if(!result){
 					return new Response(JSON.stringify({message: "Invalid voucher"}), {headers: {'content-type': 'application/json', 'status': 400}});
 				}
+				// no need to await
+				sendNotification(event.locals.user, NotificationType.USE_VOUCHER, {
+					voucher: {code: result.code, value: result.amount},
+					balanceBefore: event.locals.user.balance,
+					balanceAfter: event.locals.user.balance + result.amount
+				});
 				return new Response(JSON.stringify(result), {headers: {'content-type': 'application/json', 'status': 200}});
 			}catch(e){
 				console.error(e);
-- 
GitLab