MIF_E31221222/sigap-website/src/applications/entities/models/user.model.ts

73 lines
1.6 KiB
TypeScript

import { z } from "zod";
export const Roles = {
ADMIN: "admin",
USER: "user",
STAFF: "staff",
};
export type Roles = typeof Roles;
export const userSchema = z.object({
id: z.string(),
email: z.string(),
emailVerified: z.boolean().default(false),
password: z.string().nullable(),
firstName: z.string().nullable(),
lastName: z.string().nullable(),
avatar: z.string().nullable(),
role: z.nativeEnum(Roles).default(Roles.USER),
createdAt: z.date(),
updatedAt: z.date(),
lastSignedIn: z.date().nullable(),
metadata: z.any().nullable(),
profile: z
.object({
id: z.string(),
userId: z.string(),
bio: z.string().nullable(),
phone: z.string().nullable(),
address: z.string().nullable(),
city: z.string().nullable(),
country: z.string().nullable(),
birthDate: z.date().nullable(),
})
.nullable(),
});
export type User = z.infer<typeof userSchema>;
export const userInsertSchema = userSchema.pick({
email: true,
password: true,
firstName: true,
lastName: true,
role: true,
profile: true,
});
export type UserInsert = z.infer<typeof userInsertSchema>;
export const signInSchema = z.object({
email: z.string(),
password: z.string(),
phone: z.string(),
username: z.string(),
});
export type SignIn = z.infer<typeof signInSchema>;
export const signInWithPasswordlessSchema = signInSchema.pick({
email: true,
});
export type SignInWithOtp = z.infer<typeof signInWithPasswordlessSchema>;
export interface SignInResponse {
success: boolean;
message?: string;
error?: string;
errors?: Record<string, string>;
redirectTo?: string;
}