feat(api): stricter user data api types checking

This commit is contained in:
Dominik 2025-06-23 10:40:28 +02:00
parent 280fa57e45
commit 16b878a2e9
Signed by: dominik
GPG key ID: 06A4003FC5049644
3 changed files with 3730 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import {
newUserEmailServerSchema, newUserEmailServerSchema,
newUserNameServerSchema, newUserNameServerSchema,
passwordSchema, passwordSchema,
timezoneSchema,
} from '@/app/api/user/validation'; } from '@/app/api/user/validation';
// ---------------------------------------- // ----------------------------------------
@ -17,8 +18,8 @@ export const updateUserServerSchema = zod.object({
first_name: firstNameSchema.optional(), first_name: firstNameSchema.optional(),
last_name: lastNameSchema.optional(), last_name: lastNameSchema.optional(),
email: newUserEmailServerSchema.optional(), email: newUserEmailServerSchema.optional(),
image: zod.string().optional(), image: zod.url().optional(),
timezone: zod.string().optional(), timezone: timezoneSchema.optional(),
}); });
export const updateUserPasswordServerSchema = zod.object({ export const updateUserPasswordServerSchema = zod.object({

View file

@ -1,6 +1,7 @@
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'; import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
import { prisma } from '@/prisma'; import { prisma } from '@/prisma';
import zod from 'zod/v4'; import zod from 'zod/v4';
import { allTimeZones } from '@/lib/timezones';
extendZodWithOpenApi(zod); extendZodWithOpenApi(zod);
@ -107,6 +108,17 @@ export const passwordSchema = zod
'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character', 'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character',
); );
// ----------------------------------------
//
// Timezone Validation
//
// ----------------------------------------
export const timezoneSchema = zod
.enum(allTimeZones)
.openapi('Timezone', {
description: 'Valid timezone from the list of supported timezones',
});
// ---------------------------------------- // ----------------------------------------
// //
// User Schema Validation (for API responses) // User Schema Validation (for API responses)
@ -119,8 +131,8 @@ export const FullUserSchema = zod
first_name: zod.string().nullish(), first_name: zod.string().nullish(),
last_name: zod.string().nullish(), last_name: zod.string().nullish(),
email: zod.email(), email: zod.email(),
image: zod.string().nullish(), image: zod.url().nullish(),
timezone: zod.string(), timezone: zod.string().refine((i) => (allTimeZones as string[]).includes(i)).nullish(),
created_at: zod.date(), created_at: zod.date(),
updated_at: zod.date(), updated_at: zod.date(),
}) })

3713
src/lib/timezones.ts Normal file

File diff suppressed because it is too large Load diff