add custom matches

This commit is contained in:
2026-03-09 20:28:04 +01:00
parent 8d1cd49339
commit 6b416dce31
24 changed files with 3289 additions and 55 deletions

View File

@@ -0,0 +1,36 @@
import { json, error } from '@sveltejs/kit';
import { createInvite, getInvitesForUser } from '$lib/server/match/invites';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user) error(401, 'Not logged in');
const invites = await getInvitesForUser(locals.user.id);
return json(invites);
};
export const POST: RequestHandler = async ({ request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const body = await request.json();
const { creatorTeamId, invitedTeamId, config, mappoolId, name, message, scheduledAt } = body;
if (!creatorTeamId || !invitedTeamId || !config || !mappoolId) {
error(400, 'Missing required fields');
}
try {
const invite = await createInvite({
createdBy: locals.user.id,
creatorTeamId,
invitedTeamId,
config,
mappoolId,
name,
message,
scheduledAt: scheduledAt ? new Date(scheduledAt) : null
});
return json(invite, { status: 201 });
} catch (e: any) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,14 @@
import { json, error } from '@sveltejs/kit';
import { acceptInvite } from '$lib/server/match/invites';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Not logged in');
try {
const match = await acceptInvite(params.id, locals.user.id);
return json(match);
} catch (e: any) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,14 @@
import { json, error } from '@sveltejs/kit';
import { cancelInvite } from '$lib/server/match/invites';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Not logged in');
try {
await cancelInvite(params.id, locals.user.id);
return json({ success: true });
} catch (e: any) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,14 @@
import { json, error } from '@sveltejs/kit';
import { declineInvite } from '$lib/server/match/invites';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Not logged in');
try {
await declineInvite(params.id, locals.user.id);
return json({ success: true });
} catch (e: any) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,13 @@
import { json, error } from '@sveltejs/kit';
import { getNotifications } from '$lib/server/notifications';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals, url }) => {
if (!locals.user) error(401, 'Not logged in');
const limit = parseInt(url.searchParams.get('limit') ?? '50');
const offset = parseInt(url.searchParams.get('offset') ?? '0');
const notifications = await getNotifications(locals.user.id, { limit, offset });
return json(notifications);
};

View File

@@ -0,0 +1,9 @@
import { json, error } from '@sveltejs/kit';
import { getUnreadCount } from '$lib/server/notifications';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user) error(401, 'Not logged in');
const count = await getUnreadCount(locals.user.id);
return json({ count });
};

View File

@@ -0,0 +1,19 @@
import { json, error } from '@sveltejs/kit';
import { markRead, markAllRead } from '$lib/server/notifications';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const body = await request.json();
if (body.all) {
await markAllRead(locals.user.id);
} else if (body.notificationId) {
await markRead(body.notificationId, locals.user.id);
} else {
error(400, 'Provide notificationId or { all: true }');
}
return json({ success: true });
};