Skip to content

Commit 715c08d

Browse files
Merge pull request #52 from call-0f-code/interview-pagination
Add Interview Filters
2 parents 0a91c6b + 574cd06 commit 715c08d

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/controllers/interview.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ import { ApiError } from "../utils/apiError";
55
export const getInterviews = async (req: Request, res: Response) => {
66
const page = parseInt(req.query.page as string) || 1;
77
const limit = parseInt(req.query.limit as string) || 10;
8+
const verdict = (req.query.verdict as string) || "All";
9+
const validVerdicts = ["All", "Selected", "Rejected", "Pending"]
810

911
if(isNaN(page) || page<1){
1012
throw new ApiError("Page must be greater than or equal to 1",400);
1113
}
1214
if(isNaN(limit) || limit<1 || limit>100){
1315
throw new ApiError("Limit must be between 1 to 100",400)
1416
}
17+
if(!validVerdicts.includes(verdict)){
18+
throw new ApiError("Invalid verdict",400);
19+
}
1520

16-
const { interviews, total } = await interviewService.getInterviews(page, limit);
21+
const { interviews, total } = await interviewService.getInterviews(page, limit, verdict);
1722

1823
return res.status(200).json({
1924
success: true,
2025
data: interviews,
2126
page,
2227
limit,
28+
verdict,
2329
total,
2430
totalPages: Math.ceil(total / limit),
2531
});

src/services/interview.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { prisma } from "../db/client"
22

3-
export const getInterviews = async (page: number = 1, limit: number = 10) => {
3+
export const getInterviews = async (page: number = 1, limit: number = 10, verdict : string = "All") => {
44
const skip = (page - 1) * limit;
55

6+
const where : any = {}
7+
if(verdict !== "All"){
8+
where.verdict = verdict
9+
}
10+
611
const [interviews, total] = await Promise.all([
712
prisma.interviewExperience.findMany({
13+
where,
814
skip,
915
take: limit,
1016
include: {
@@ -21,7 +27,7 @@ export const getInterviews = async (page: number = 1, limit: number = 10) => {
2127
},
2228
}),
2329

24-
prisma.interviewExperience.count(),
30+
prisma.interviewExperience.count({where}),
2531
]);
2632

2733
const formattedInterviews = interviews.map(

tests/Interview.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ describe('getInterviews', () => {
4949
data: mockInterviews,
5050
page: 1,
5151
limit: 10,
52+
verdict: "All",
5253
total: 1,
5354
totalPages: Math.ceil(1 / 10),
5455
});
5556
});
5657
});
5758

59+
5860
describe('getInterviewById', () => {
5961
it('should return 200 and the interview if found', async () => {
6062
const req: any = {

0 commit comments

Comments
 (0)