Spaces:
Runtime error
Runtime error
Download src/app/api/user/validations.ts from shyota/better-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/shyota/better-chatbot/resolve/main/src/app/api/user/validations.ts
- Command line
-
hf download hf://spaces/shyota/better-chatbot/src/app/api/user/validations.ts
-
curl -L -o validations.ts https://huggingface.co/spaces/shyota/better-chatbot/resolve/main/src/app/api/user/validations.ts
1.9 kB
| import { z } from "zod"; | |
| import { USER_ROLES, UserRoleNames } from "app-types/roles"; | |
| import { ActionState } from "lib/action-utils"; | |
| import { BasicUserWithLastLogin } from "app-types/user"; | |
| import { passwordSchema } from "lib/validations/password"; | |
| export const UpdateUserRoleSchema = z.object({ | |
| userId: z.string().uuid("Invalid user ID"), | |
| role: z | |
| .enum(Object.values(USER_ROLES) as [UserRoleNames, ...UserRoleNames[]]) | |
| .optional(), | |
| }); | |
| export const UpdateUserPasswordError = { | |
| PASSWORD_MISMATCH: "Passwords do not match", | |
| CURRENT_PASSWORD_REQUIRED: "Current password is required", | |
| } as const; | |
| export type UpdateUserPasswordError = | |
| (typeof UpdateUserPasswordError)[keyof typeof UpdateUserPasswordError]; | |
| export const UpdateUserDetailsSchema = z.object({ | |
| userId: z.uuid("Invalid user ID"), | |
| name: z.string().min(1, "Name is required").max(100, "Name is too long"), | |
| email: z.email("Invalid email address").optional(), | |
| image: z.string().optional(), | |
| }); | |
| export const DeleteUserSchema = z.object({ | |
| userId: z.uuid("Invalid user ID"), | |
| }); | |
| export const UpdateUserPasswordSchema = z | |
| .object({ | |
| userId: z.string().uuid("Invalid user ID"), | |
| newPassword: passwordSchema, | |
| confirmPassword: passwordSchema, | |
| currentPassword: z.string().optional(), | |
| }) | |
| .superRefine((data, ctx) => { | |
| if (data.newPassword !== data.confirmPassword) { | |
| ctx.addIssue({ | |
| code: "custom", | |
| message: UpdateUserPasswordError.PASSWORD_MISMATCH, | |
| }); | |
| } | |
| }); | |
| export type UpdateUserRoleActionState = ActionState & { | |
| user?: BasicUserWithLastLogin | null; | |
| }; | |
| export type DeleteUserActionState = ActionState & { | |
| redirect?: string; | |
| }; | |
| export type UpdateUserActionState = ActionState & { | |
| user?: BasicUserWithLastLogin | null; | |
| currentUserUpdated?: boolean; | |
| }; | |
| export type UpdateUserPasswordActionState = ActionState & { | |
| error?: UpdateUserPasswordError; | |
| }; | |