Update: all queries involving image now use ImageQueryValidationSchema

This commit is contained in:
Aaron William Po
2023-11-11 20:30:07 -05:00
parent 3ea9f67f16
commit d48d9a8886
21 changed files with 180 additions and 49 deletions

View File

@@ -36,7 +36,16 @@ const createNewBeerPost = ({
ibu: true,
createdAt: true,
updatedAt: true,
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
brewery: { select: { id: true, name: true } },
style: { select: { id: true, name: true, description: true } },
postedBy: { select: { id: true, username: true } },

View File

@@ -19,7 +19,16 @@ const deleteBeerPostById = ({
id: true,
name: true,
updatedAt: true,
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
style: { select: { id: true, name: true, description: true } },
postedBy: { select: { id: true, username: true } },
brewery: { select: { id: true, name: true } },

View File

@@ -25,7 +25,16 @@ const editBeerPostById = ({
ibu: true,
createdAt: true,
updatedAt: true,
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
brewery: { select: { id: true, name: true } },
style: { select: { id: true, name: true, description: true } },
postedBy: { select: { id: true, username: true } },

View File

@@ -25,7 +25,16 @@ const getAllBeerPosts = ({
style: { select: { name: true, id: true, description: true } },
brewery: { select: { name: true, id: true } },
postedBy: { select: { id: true, username: true } },
beerImages: { select: { path: true, caption: true, id: true, alt: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
},
take: pageSize,
skip: (pageNum - 1) * pageSize,

View File

@@ -19,7 +19,16 @@ const getBeerPostById = async (
postedBy: { select: { username: true, id: true } },
brewery: { select: { name: true, id: true } },
style: { select: { name: true, id: true, description: true } },
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
},
where: { id },
});

View File

@@ -28,7 +28,16 @@ const getBeerPostsByBeerStyleId = async ({
postedBy: { select: { username: true, id: true } },
brewery: { select: { name: true, id: true } },
style: { select: { name: true, id: true, description: true } },
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
},
});

View File

@@ -28,7 +28,16 @@ const getBeerPostsByBeerStyleId = async ({
postedBy: { select: { username: true, id: true } },
brewery: { select: { name: true, id: true } },
style: { select: { name: true, id: true, description: true } },
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
},
});

View File

@@ -37,7 +37,16 @@ const getBeerRecommendations = async ({
style: { select: { name: true, id: true, description: true } },
brewery: { select: { name: true, id: true } },
postedBy: { select: { id: true, username: true } },
beerImages: { select: { path: true, caption: true, id: true, alt: true } },
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
},
take,
skip,

View File

@@ -1,3 +1,4 @@
import ImageQueryValidationSchema from '@/services/schema/ImageSchema/ImageQueryValidationSchema';
import { z } from 'zod';
const BeerPostQueryResult = z.object({
@@ -5,9 +6,7 @@ const BeerPostQueryResult = z.object({
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() }),
),
beerImages: z.array(ImageQueryValidationSchema),
ibu: z.number(),
abv: z.number(),
style: z.object({ id: z.string(), name: z.string(), description: z.string() }),

View File

@@ -37,7 +37,16 @@ const createNewBreweryPost = async ({
createdAt: true,
dateEstablished: true,
postedBy: { select: { id: true, username: true } },
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
breweryImages: {
select: {
path: true,
caption: true,
id: true,
alt: true,
createdAt: true,
updatedAt: true,
},
},
location: {
select: {
city: true,

View File

@@ -29,7 +29,16 @@ const getAllBreweryPosts = async ({
description: true,
name: true,
postedBy: { select: { username: true, id: true } },
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
breweryImages: {
select: {
path: true,
caption: true,
id: true,
alt: true,
createdAt: true,
updatedAt: true,
},
},
createdAt: true,
dateEstablished: true,
},

View File

@@ -19,7 +19,16 @@ const getBreweryPostById = async (id: string) => {
},
description: true,
name: true,
breweryImages: { select: { path: true, caption: true, id: true, alt: true } },
breweryImages: {
select: {
path: true,
caption: true,
id: true,
alt: true,
createdAt: true,
updatedAt: true,
},
},
postedBy: { select: { username: true, id: true } },
createdAt: true,
dateEstablished: true,

View File

@@ -1,3 +1,4 @@
import ImageQueryValidationSchema from '@/services/schema/ImageSchema/ImageQueryValidationSchema';
import { z } from 'zod';
const BreweryPostQueryResult = z.object({
@@ -12,9 +13,7 @@ const BreweryPostQueryResult = z.object({
stateOrProvince: z.string().nullable(),
}),
postedBy: z.object({ id: z.string(), username: z.string() }),
breweryImages: z.array(
z.object({ path: z.string(), caption: z.string(), id: z.string(), alt: z.string() }),
),
breweryImages: z.array(ImageQueryValidationSchema),
createdAt: z.coerce.date(),
dateEstablished: z.coerce.date(),
});

View File

@@ -1,3 +1,4 @@
import ImageQueryValidationSchema from '@/services/schema/ImageSchema/ImageQueryValidationSchema';
import { z } from 'zod';
const GetUserSchema = z.object({
@@ -12,16 +13,7 @@ const GetUserSchema = z.object({
accountIsVerified: z.boolean(),
role: z.enum(['USER', 'ADMIN']),
bio: z.string().nullable(),
userAvatar: z
.object({
id: z.string().cuid(),
path: z.string().url(),
alt: z.string(),
caption: z.string(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date().nullable(),
})
.nullable(),
userAvatar: ImageQueryValidationSchema.nullable(),
});
export default GetUserSchema;

View File

@@ -1,23 +1,17 @@
import { z } from 'zod';
import ImageQueryValidationSchema from '../ImageSchema/ImageQueryValidationSchema';
const CommentQueryResult = z.object({
id: z.string().cuid(),
content: z.string().min(1).max(500),
rating: z.number().int().min(1).max(5),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date().nullable(),
postedBy: z.object({
id: z.string().cuid(),
username: z.string().min(1).max(50),
userAvatar: z
.object({
id: z.string().cuid(),
path: z.string().url(),
alt: z.string().min(1).max(50),
caption: z.string().min(1).max(50),
})
.nullable(),
userAvatar: ImageQueryValidationSchema.nullable(),
}),
updatedAt: z.coerce.date().nullable(),
});
export default CommentQueryResult;

View File

@@ -0,0 +1,12 @@
import { z } from 'zod';
const ImageQueryValidationSchema = z.object({
id: z.string().cuid(),
path: z.string().url(),
alt: z.string(),
caption: z.string(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date().nullable(),
});
export default ImageQueryValidationSchema;