feat: implement notification system

This commit is contained in:
Face 2025-06-11 18:37:03 +03:00
parent de3f8a4929
commit e61c41e414
19 changed files with 883 additions and 3196 deletions

View file

@ -3,6 +3,8 @@ import { error, json } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { user, userPortfolio, coin, transaction } from '$lib/server/db/schema';
import { eq, and } from 'drizzle-orm';
import { createNotification } from '$lib/server/notification';
import { formatValue } from '$lib/utils';
import type { RequestHandler } from './$types';
interface TransferRequest {
@ -19,7 +21,7 @@ export const POST: RequestHandler = async ({ request }) => {
if (!session?.user) {
throw error(401, 'Not authenticated');
} try {
} try {
const { recipientUsername, type, amount, coinSymbol }: TransferRequest = await request.json();
if (!recipientUsername || !type || !amount || typeof amount !== 'number' || !Number.isFinite(amount) || amount <= 0) {
@ -123,6 +125,15 @@ export const POST: RequestHandler = async ({ request }) => {
recipientUserId: recipientData.id
});
(async () => {
await createNotification(
recipientData.id.toString(),
'TRANSFER',
'Money received!',
`You received ${formatValue(amount)} from @${senderData.username}`,
);
})();
return json({
success: true,
type: 'CASH',
@ -247,6 +258,15 @@ export const POST: RequestHandler = async ({ request }) => {
recipientUserId: recipientData.id
});
(async () => {
await createNotification(
recipientData.id.toString(),
'TRANSFER',
'Coins received!',
`You received ${amount.toFixed(6)} *${coinData.symbol} from @${senderData.username}`,
);
})();
return json({
success: true,
type: 'COIN',