update models

This commit is contained in:
Guillaume Dorce 2022-08-25 12:12:41 +02:00
parent 038015136f
commit 431a5efdbb
2 changed files with 37 additions and 7 deletions

19
src/models/PostModel.ts Normal file
View File

@ -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<Post> = z.object({
id: z.number(),
title: z.string(),
content: z.string().optional(),
picture: z.string().optional(),
authorId: z.number(),
});
export { Post };

View File

@ -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<User> = 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 };