Skip to content
Snippets Groups Projects
Commit b97d9bbf authored by Aaron Dötsch's avatar Aaron Dötsch
Browse files

Implement withdraw and deposit notificaions

parent ef5b6b90
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ import { fail } from "@sveltejs/kit";
import { createTransaction } from "../../api/transactions";
import { ChannelType } from "$lib/server/notifications/channelTypes";
import { createNotificationChannel, updateNotificationChannel } from "../../api/notificationChannels";
import { sendNotification } from "$lib/server/notifications/handler";
import { NotificationType } from "$lib/notifications/notificationTypes";
export const load = async ({ params }) => {
const { id } = params;
......@@ -42,6 +44,21 @@ export const actions = {
const amount = parseInt(data.get('amount'));
if(Number.isNaN(amount) || !Number.isInteger(amount)) return fail(400, { error: "Invalid form data" });
const user = await createTransaction(userId, amount, event.locals.user.id);
if(amount < 0){
// no need to await
sendNotification(user.id, NotificationType.WITHDRAW, {
amount: -amount,
balanceAfter: user.balance,
balanceBefore: user.balance - amount
});
}else{
// no need to await
sendNotification(user.id, NotificationType.DEPOSIT, {
amount,
balanceAfter: user.balance,
balanceBefore: user.balance - amount
});
}
delete user.createdAt;
delete user.updatedAt;
return { success: !!user, user };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment