diff --git a/src/models/PostModel.ts b/src/models/PostModel.ts new file mode 100644 index 0000000..9ae493e --- /dev/null +++ b/src/models/PostModel.ts @@ -0,0 +1,19 @@ +import { z } from 'zod'; + +interface Post { + id: number; + title: string; + content?: string | undefined; + picture?: string | undefined; + authorId: number; +} + +const Post: z.ZodType = z.object({ + id: z.number(), + title: z.string(), + content: z.string().optional(), + picture: z.string().optional(), + authorId: z.number(), +}); + +export { Post }; diff --git a/src/models/UserModel.ts b/src/models/UserModel.ts index 566a132..5a3e4bb 100644 --- a/src/models/UserModel.ts +++ b/src/models/UserModel.ts @@ -1,13 +1,24 @@ import { z } from 'zod'; +import { Post } from './PostModel'; -const UserModel = z.object({ - id: z.string().optional(), +interface User { + id?: number | undefined; + email: string; + password: string; + firstName: string; + lastName: string; + role?: string | undefined; + posts?: Post[] | undefined; +} + +const User: z.ZodType = z.object({ + id: z.number().optional(), email: z.string().email(), password: z.string(), - firstname: z.string(), - lastname: z.string(), - role: z.string().default('user'), - posts: z.array(z.string()).optional(), + firstName: z.string(), + lastName: z.string(), + role: z.string().optional(), + posts: z.array(Post).optional(), }); -export default UserModel; +export { User };