feat(api): add swagger docs, /api/user/me GET and PUT endpoints

This commit is contained in:
Dominik 2025-06-11 22:43:37 +02:00
parent c2861047d0
commit 57e420f572
Signed by: dominik
GPG key ID: 06A4003FC5049644
10 changed files with 2980 additions and 265 deletions

View file

@ -1,37 +1,39 @@
import zod from 'zod';
export const userEmailSchema = zod
.string()
.email('Invalid email address')
.min(3, 'Email is required');
export const userFirstNameSchema = zod
.string()
.min(1, 'First name is required')
.max(32, 'First name must be at most 32 characters long');
export const userLastNameSchema = zod
.string()
.min(1, 'Last name is required')
.max(32, 'Last name must be at most 32 characters long');
export const userNameSchema = zod
.string()
.min(3, 'Username is required')
.max(32, 'Username must be at most 32 characters long')
.regex(
/^[a-zA-Z0-9_]+$/,
'Username can only contain letters, numbers, and underscores',
);
export const loginSchema = zod.object({
email: zod
.string()
.email('Invalid email address')
.min(3, 'Email is required')
.or(
zod
.string()
.min(3, 'Username is required')
.max(32, 'Username must be at most 32 characters long')
.regex(
/^[a-zA-Z0-9_]+$/,
'Username can only contain letters, numbers, and underscores',
),
),
email: userEmailSchema.or(userNameSchema),
password: zod.string().min(1, 'Password is required'),
});
export const registerSchema = zod
.object({
firstName: zod
.string()
.min(1, 'First name is required')
.max(32, 'First name must be at most 32 characters long'),
lastName: zod
.string()
.min(1, 'Last name is required')
.max(32, 'Last name must be at most 32 characters long'),
email: zod
.string()
.email('Invalid email address')
.min(3, 'Email is required'),
firstName: userFirstNameSchema,
lastName: userLastNameSchema,
email: userEmailSchema,
password: zod
.string()
.min(8, 'Password must be at least 8 characters long')
@ -40,14 +42,7 @@ export const registerSchema = zod
.string()
.min(8, 'Password must be at least 8 characters long')
.max(128, 'Password must be at most 128 characters long'),
username: zod
.string()
.min(3, 'Username is required')
.max(32, 'Username must be at most 32 characters long')
.regex(
/^[a-zA-Z0-9_]+$/,
'Username can only contain letters, numbers, and underscores',
),
username: userNameSchema,
})
.refine((data) => data.password === data.confirmPassword, {
message: 'Passwords do not match',