add custom matches
This commit is contained in:
36
src/routes/api/invites/+server.ts
Normal file
36
src/routes/api/invites/+server.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
14
src/routes/api/invites/[id]/accept/+server.ts
Normal file
14
src/routes/api/invites/[id]/accept/+server.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
14
src/routes/api/invites/[id]/cancel/+server.ts
Normal file
14
src/routes/api/invites/[id]/cancel/+server.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
14
src/routes/api/invites/[id]/decline/+server.ts
Normal file
14
src/routes/api/invites/[id]/decline/+server.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
13
src/routes/api/notifications/+server.ts
Normal file
13
src/routes/api/notifications/+server.ts
Normal 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);
|
||||
};
|
||||
9
src/routes/api/notifications/count/+server.ts
Normal file
9
src/routes/api/notifications/count/+server.ts
Normal 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 });
|
||||
};
|
||||
19
src/routes/api/notifications/read/+server.ts
Normal file
19
src/routes/api/notifications/read/+server.ts
Normal 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 });
|
||||
};
|
||||
Reference in New Issue
Block a user