Refactor: update types for brewery comments

This commit is contained in:
Aaron William Po
2023-10-07 15:21:57 -04:00
parent 2ee12d351f
commit 3b626e2f95
13 changed files with 3388 additions and 3517 deletions

View File

@@ -1,7 +1,7 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import CreateCommentValidationSchema from '../schema/CommentSchema/CreateCommentValidationSchema';
import BeerCommentQueryResult from './schema/BeerCommentQueryResult';
import CommentQueryResult from '../schema/CommentSchema/CommentQueryResult';
const CreateNewBeerCommentServiceSchema = CreateCommentValidationSchema.extend({
userId: z.string().cuid(),
@@ -15,7 +15,7 @@ const createNewBeerComment = async ({
rating,
beerPostId,
userId,
}: CreateNewBeerCommentArgs): Promise<z.infer<typeof BeerCommentQueryResult>> => {
}: CreateNewBeerCommentArgs): Promise<z.infer<typeof CommentQueryResult>> => {
return DBClient.instance.beerComment.create({
data: {
content,

View File

@@ -1,6 +1,6 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerCommentQueryResult from './schema/BeerCommentQueryResult';
import CommentQueryResult from '../schema/CommentSchema/CommentQueryResult';
interface EditBeerCommentByIdArgs {
id: string;
@@ -12,7 +12,7 @@ const editBeerCommentById = async ({
id,
content,
rating,
}: EditBeerCommentByIdArgs): Promise<z.infer<typeof BeerCommentQueryResult>> => {
}: EditBeerCommentByIdArgs): Promise<z.infer<typeof CommentQueryResult>> => {
return DBClient.instance.beerComment.update({
where: { id },
data: { content, rating, updatedAt: new Date() },

View File

@@ -1,6 +1,6 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerCommentQueryResult from './schema/BeerCommentQueryResult';
import CommentQueryResult from '../schema/CommentSchema/CommentQueryResult';
interface FindBeerCommentArgs {
beerCommentId: string;
@@ -8,7 +8,7 @@ interface FindBeerCommentArgs {
const findBeerCommentById = async ({
beerCommentId,
}: FindBeerCommentArgs): Promise<z.infer<typeof BeerCommentQueryResult> | null> => {
}: FindBeerCommentArgs): Promise<z.infer<typeof CommentQueryResult> | null> => {
return DBClient.instance.beerComment.findUnique({
where: { id: beerCommentId },
select: {

View File

@@ -23,6 +23,7 @@ const getAllBeerComments = async ({
content: true,
rating: true,
createdAt: true,
updatedAt: true,
postedBy: { select: { id: true, username: true, createdAt: true } },
},
});

View File

@@ -1,15 +0,0 @@
import { z } from 'zod';
const BeerCommentQueryResult = z.object({
id: z.string().cuid(),
content: z.string(),
rating: z.number(),
postedBy: z.object({
id: z.string().cuid(),
username: z.string(),
}),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date().nullable(),
});
export default BeerCommentQueryResult;