feat(api): stricter user data api types checking
This commit is contained in:
parent
280fa57e45
commit
16b878a2e9
3 changed files with 3730 additions and 4 deletions
|
@ -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({
|
||||||
|
|
|
@ -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
3713
src/lib/timezones.ts
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue