initial commit
Some checks failed
deploy / build-and-deploy (push) Failing after 21s

This commit is contained in:
2025-05-18 13:16:20 +02:00
commit 60f3f8a096
148 changed files with 17900 additions and 0 deletions

88
src/actions/user.ts Normal file
View File

@@ -0,0 +1,88 @@
import { ActionError, defineAction } from 'astro:actions';
import { z } from 'astro:schema';
import { db } from '@db/database.ts';
import { Session } from '@util/session.ts';
import { Permissions } from '@util/permissions.ts';
export const user = {
addUser: defineAction({
input: z.object({
firstname: z.string(),
lastname: z.string(),
birthday: z.string().date(),
telephone: z.string().nullable(),
username: z.string(),
uuid: z.string().nullable()
}),
handler: async (input, context) => {
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
if (await db.existsUser({ username: input.username })) {
throw new ActionError({
code: 'CONFLICT',
message: 'Der Benutzername ist bereits registriert'
});
}
const { id } = await db.addUser({
firstname: input.firstname,
lastname: input.lastname,
birthday: input.birthday,
telephone: input.telephone,
username: input.username,
uuid: input.uuid
});
return {
id: id
};
}
}),
editUser: defineAction({
input: z.object({
id: z.number(),
firstname: z.string(),
lastname: z.string(),
birthday: z.string().date(),
telephone: z.string().nullable(),
username: z.string(),
uuid: z.string().nullable()
}),
handler: async (input, context) => {
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
const user = await db.existsUser({ username: input.username });
if (user && user.id !== input.id) {
throw new ActionError({
code: 'CONFLICT',
message: 'Ein Spieler mit dem Benutzernamen existiert bereits'
});
}
await db.editUser({
id: input.id,
firstname: input.firstname,
lastname: input.lastname,
birthday: input.birthday,
telephone: input.telephone,
username: input.username,
uuid: input.uuid
});
}
}),
users: defineAction({
input: z.object({
username: z.string().nullish(),
limit: z.number().optional()
}),
handler: async (input, context) => {
Session.actionSessionFromCookies(context.cookies, Permissions.Users);
const users = await db.getUsers(input);
return {
users: users
};
}
})
};