Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/controllers/interview.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ import { ApiError } from "../utils/apiError";
export const getInterviews = async (req: Request, res: Response) => {
const page = parseInt(req.query.page as string) || 1;
const limit = parseInt(req.query.limit as string) || 10;
const verdict = (req.query.verdict as string) || "All";
const validVerdicts = ["All", "Selected", "Rejected", "Pending"]

if(isNaN(page) || page<1){
throw new ApiError("Page must be greater than or equal to 1",400);
}
if(isNaN(limit) || limit<1 || limit>100){
throw new ApiError("Limit must be between 1 to 100",400)
}
if(!validVerdicts.includes(verdict)){
throw new ApiError("Invalid verdict",400);
}

const { interviews, total } = await interviewService.getInterviews(page, limit);
const { interviews, total } = await interviewService.getInterviews(page, limit, verdict);

return res.status(200).json({
success: true,
data: interviews,
page,
limit,
verdict,
total,
totalPages: Math.ceil(total / limit),
});
Expand Down
10 changes: 8 additions & 2 deletions src/services/interview.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { prisma } from "../db/client"

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

const where : any = {}
if(verdict !== "All"){
where.verdict = verdict
}
Comment on lines +6 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Replace any type with proper Prisma typing.

Using any defeats TypeScript's type safety and is flagged by static analysis. The where clause should use Prisma's generated types.

Apply this diff to use proper typing:

-const where : any = {}
+const where: Prisma.InterviewExperienceWhereInput = {}
 if(verdict !== "All"){
   where.verdict = verdict
 }

You'll need to import the Prisma namespace at the top of the file:

-import { prisma } from "../db/client"
+import { prisma, Prisma } from "../db/client"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const where : any = {}
if(verdict !== "All"){
where.verdict = verdict
}
const where: Prisma.InterviewExperienceWhereInput = {}
if(verdict !== "All"){
where.verdict = verdict
}
🧰 Tools
🪛 ESLint

[error] 6-6: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

🤖 Prompt for AI Agents
In src/services/interview.service.ts around lines 6 to 9, the variable "where"
is currently typed as "any" which bypasses TypeScript/Prisma typings; change it
to the appropriate Prisma generated type (e.g., Prisma.InterviewWhereInput) and
update usage accordingly so "where.verdict = verdict" remains valid. Add an
import for the Prisma namespace at the top of the file (import { Prisma } from
'@prisma/client') and declare "const where: Prisma.InterviewWhereInput = {}" (or
the exact model WhereInput name if different), preserving the conditional
assignment when verdict !== "All". Ensure no other "any" remains for the where
clause.


const [interviews, total] = await Promise.all([
prisma.interviewExperience.findMany({
where,
skip,
take: limit,
include: {
Expand All @@ -21,7 +27,7 @@ export const getInterviews = async (page: number = 1, limit: number = 10) => {
},
}),

prisma.interviewExperience.count(),
prisma.interviewExperience.count({where}),
]);

const formattedInterviews = interviews.map(
Expand Down
2 changes: 2 additions & 0 deletions tests/Interview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ describe('getInterviews', () => {
data: mockInterviews,
page: 1,
limit: 10,
verdict: "All",
total: 1,
totalPages: Math.ceil(1 / 10),
});
});
});


describe('getInterviewById', () => {
it('should return 200 and the interview if found', async () => {
const req: any = {
Expand Down