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:
35
services/BeerPost/getAllBeerPosts.ts
Normal file
35
services/BeerPost/getAllBeerPosts.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import DBClient from '@/prisma/client';
|
||||
import BeerPostQueryResult from './types/BeerPostQueryResult';
|
||||
|
||||
const prisma = DBClient.instance;
|
||||
|
||||
const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
|
||||
const skip = (pageNum - 1) * pageSize;
|
||||
|
||||
const beerPosts: BeerPostQueryResult[] = await prisma.beerPost.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
brewery: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
description: true,
|
||||
postedBy: {
|
||||
select: {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
take: pageSize,
|
||||
skip,
|
||||
});
|
||||
|
||||
return beerPosts;
|
||||
};
|
||||
|
||||
export default getAllBeerPosts;
|
||||
33
services/BeerPost/getBeerPostById.ts
Normal file
33
services/BeerPost/getBeerPostById.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import DBClient from '@/prisma/client';
|
||||
import BeerPostQueryResult from './types/BeerPostQueryResult';
|
||||
|
||||
const prisma = DBClient.instance;
|
||||
|
||||
const getBeerPostById = async (id: string) => {
|
||||
const beerPost: BeerPostQueryResult | null = await prisma.beerPost.findFirst({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
brewery: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
postedBy: {
|
||||
select: {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
|
||||
return beerPost;
|
||||
};
|
||||
|
||||
export default getBeerPostById;
|
||||
14
services/BeerPost/types/BeerPostQueryResult.ts
Normal file
14
services/BeerPost/types/BeerPostQueryResult.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export default interface BeerPostQueryResult {
|
||||
id: string;
|
||||
name: string;
|
||||
brewery: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
description: string;
|
||||
postedBy: {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user