BeerPostQueryResult type now inferred from zod schema

This commit is contained in:
Aaron William Po
2023-02-20 14:26:58 -05:00
parent 4cd2ab476f
commit c818dc6525
16 changed files with 75 additions and 58 deletions

View File

@@ -1,28 +1,36 @@
export default interface BeerPostQueryResult {
id: string;
name: string;
brewery: {
id: string;
name: string;
};
description: string;
beerImages: {
path: string;
caption: string;
id: string;
alt: string;
}[];
import { z } from 'zod';
ibu: number;
abv: number;
type: {
id: string;
name: string;
};
postedBy: {
id: string;
username: string;
};
export const beerPostQueryResultSchema = z.object({
id: z.string(),
name: z.string(),
brewery: z.object({
id: z.string(),
name: z.string(),
}),
description: z.string(),
beerImages: z.array(
z.object({
path: z.string(),
caption: z.string(),
id: z.string(),
alt: z.string(),
}),
),
ibu: z.number(),
abv: z.number(),
type: z.object({
id: z.string(),
name: z.string(),
}),
postedBy: z.object({
id: z.string(),
username: z.string(),
}),
createdAt: z.date(),
});
createdAt: Date;
}
export const beerPostQueryResultArraySchema = z.array(beerPostQueryResultSchema);
export type BeerPostQueryResult = z.infer<typeof beerPostQueryResultSchema>;
export type BeerPostQueryResultArray = z.infer<typeof beerPostQueryResultArraySchema>;