mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Add beer post, brewery post GET service and page
Add prettier, eslint config
This commit is contained in:
21
services/BreweryPost/getAllBreweryPosts.ts
Normal file
21
services/BreweryPost/getAllBreweryPosts.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import DBClient from '@/prisma/client';
|
||||
import GetAllBreweryPostsQueryResult 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 } },
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return breweryPosts;
|
||||
};
|
||||
|
||||
export default getAllBreweryPosts;
|
||||
29
services/BreweryPost/getBreweryPostById.ts
Normal file
29
services/BreweryPost/getBreweryPostById.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import DBClient from '@/prisma/client';
|
||||
import GetAllBreweryPostsQueryResult 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
|
||||
return breweryPost;
|
||||
};
|
||||
|
||||
export default getBreweryPostById;
|
||||
10
services/BreweryPost/types/BreweryPostQueryResult.ts
Normal file
10
services/BreweryPost/types/BreweryPostQueryResult.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export default interface GetAllBreweryPostsQueryResult {
|
||||
id: string;
|
||||
location: string;
|
||||
name: string;
|
||||
postedBy: {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user