scaffold create/edit beer form, scaffold beer page

This commit is contained in:
Aaron William Po
2023-01-23 20:13:25 -05:00
parent f08731de17
commit 972846f5a8
29 changed files with 776 additions and 70 deletions

View File

@@ -10,6 +10,14 @@ const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
select: {
id: true,
name: true,
type: {
select: {
name: true,
id: true,
},
},
ibu: true,
abv: true,
brewery: {
select: {
name: true,
@@ -17,10 +25,16 @@ const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
},
},
description: true,
createdAt: true,
postedBy: {
select: {
firstName: true,
lastName: true,
id: true,
username: true,
},
},
beerImages: {
select: {
url: true,
id: true,
},
},

View File

@@ -14,11 +14,25 @@ const getBeerPostById = async (id: string) => {
id: true,
},
},
ibu: true,
abv: true,
type: {
select: {
name: true,
id: true,
},
},
beerImages: {
select: {
url: true,
id: true,
},
},
createdAt: true,
description: true,
postedBy: {
select: {
firstName: true,
lastName: true,
username: true,
id: true,
},
},

View File

@@ -6,9 +6,21 @@ export default interface BeerPostQueryResult {
name: string;
};
description: string;
beerImages: {
url: string;
id: string;
}[];
ibu: number;
abv: number;
type: {
id: string;
name: string;
};
postedBy: {
id: string;
firstName: string;
lastName: string;
username: string;
};
createdAt: Date;
}

View File

@@ -1,19 +1,17 @@
import DBClient from '@/prisma/DBClient';
import GetAllBreweryPostsQueryResult from './types/BreweryPostQueryResult';
import BreweryPostQueryResult from './types/BreweryPostQueryResult';
const prisma = DBClient.instance;
const getAllBreweryPosts = async () => {
const breweryPosts: GetAllBreweryPostsQueryResult[] = await prisma.breweryPost.findMany(
{
select: {
id: true,
location: true,
name: true,
postedBy: { select: { firstName: true, lastName: true, id: true } },
},
const breweryPosts: BreweryPostQueryResult[] = await prisma.breweryPost.findMany({
select: {
id: true,
location: true,
name: true,
postedBy: { select: { firstName: true, lastName: true, id: true } },
},
);
});
return breweryPosts;
};

View File

@@ -1,27 +1,26 @@
import DBClient from '@/prisma/DBClient';
import GetAllBreweryPostsQueryResult from './types/BreweryPostQueryResult';
import BreweryPostQueryResult from './types/BreweryPostQueryResult';
const prisma = DBClient.instance;
const getBreweryPostById = async (id: string) => {
const breweryPost: GetAllBreweryPostsQueryResult | null =
await prisma.breweryPost.findFirst({
select: {
id: true,
location: true,
name: true,
postedBy: {
select: {
firstName: true,
lastName: true,
id: true,
},
const breweryPost: BreweryPostQueryResult | null = await prisma.breweryPost.findFirst({
select: {
id: true,
location: true,
name: true,
postedBy: {
select: {
firstName: true,
lastName: true,
id: true,
},
},
where: {
id,
},
});
},
where: {
id,
},
});
return breweryPost;
};

View File

@@ -1,4 +1,4 @@
export default interface GetAllBreweryPostsQueryResult {
export default interface BreweryPostQueryResult {
id: string;
location: string;
name: string;