Refactored api services into sep files. Client fix

Fixed hydration errors in beers/[id] by implementing timeDistanceState
This commit is contained in:
Aaron William Po
2023-01-31 22:38:13 -05:00
parent 0b96c8f1f5
commit 5cf2087cd1
29 changed files with 380 additions and 430 deletions

View File

@@ -0,0 +1,27 @@
export default interface BeerPostQueryResult {
id: string;
name: string;
brewery: {
id: string;
name: string;
};
description: string;
beerImages: {
url: string;
id: string;
alt: string;
}[];
ibu: number;
abv: number;
type: {
id: string;
name: string;
};
postedBy: {
id: string;
username: string;
};
createdAt: Date;
}

View File

@@ -0,0 +1,15 @@
import { BeerPost } from '@prisma/client';
type BeerRecommendationQueryResult = BeerPost & {
brewery: {
id: string;
name: string;
};
beerImages: {
id: string;
alt: string;
url: string;
}[];
};
export default BeerRecommendationQueryResult;

View File

@@ -0,0 +1,43 @@
import { z } from 'zod';
const BeerPostValidationSchema = z.object({
name: z
.string({
required_error: 'Beer name is required.',
invalid_type_error: 'Beer name must be a string.',
})
.min(1, { message: 'Beer name is required.' })
.max(100, { message: 'Beer name is too long.' }),
description: z
.string()
.min(1, { message: 'Description is required.' })
.max(500, { message: 'Description is too long.' }),
abv: z
.number({
required_error: 'ABV is required.',
invalid_type_error: 'ABV must be a number.',
})
.min(0.1, { message: 'ABV must be greater than 0.1.' })
.max(50, { message: 'ABV must be less than 50.' }),
ibu: z
.number({
required_error: 'IBU is required.',
invalid_type_error: 'IBU must be a number.',
})
.min(2, { message: 'IBU must be greater than 2.' })
.max(100, { message: 'IBU must be less than 100.' }),
typeId: z
.string({
required_error: 'Type id is required.',
invalid_type_error: 'Type id must be a string.',
})
.uuid({ message: 'Invalid type id.' }),
breweryId: z
.string({
required_error: 'Brewery id is required.',
invalid_type_error: 'Brewery id must be a string.',
})
.uuid({ message: 'Invalid brewery id.' }),
});
export default BeerPostValidationSchema;