Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JCSE Frontend #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
105 changes: 56 additions & 49 deletions backend/src/application/services/positionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,69 @@ import { Position } from '../../domain/models/Position';
const prisma = new PrismaClient();

const calculateAverageScore = (interviews: any[]) => {
if (interviews.length === 0) return 0;
const totalScore = interviews.reduce((acc, interview) => acc + (interview.score || 0), 0);
return totalScore / interviews.length;
if (interviews.length === 0) return 0;
const totalScore = interviews.reduce(
(acc, interview) => acc + (interview.score || 0),
0,
);
return totalScore / interviews.length;
};

export const getCandidatesByPositionService = async (positionId: number) => {
try {
const applications = await prisma.application.findMany({
where: { positionId },
include: {
candidate: true,
interviews: true,
interviewStep: true
}
});
try {
const applications = await prisma.application.findMany({
where: { positionId },
include: {
candidate: true,
interviews: true,
interviewStep: true,
},
});

return applications.map(app => ({
fullName: `${app.candidate.firstName} ${app.candidate.lastName}`,
currentInterviewStep: app.interviewStep.name,
averageScore: calculateAverageScore(app.interviews)
}));
} catch (error) {
console.error('Error retrieving candidates by position:', error);
throw new Error('Error retrieving candidates by position');
}
return applications.map((app) => ({
id: app.candidate.id,
applicationId: app.id,
fullName: `${app.candidate.firstName} ${app.candidate.lastName}`,
currentInterviewStep: app.interviewStep.name,
averageScore: calculateAverageScore(app.interviews),
}));
} catch (error) {
console.error('Error retrieving candidates by position:', error);
throw new Error('Error retrieving candidates by position');
}
};

export const getInterviewFlowByPositionService = async (positionId: number) => {
const positionWithInterviewFlow = await prisma.position.findUnique({
where: { id: positionId },
const positionWithInterviewFlow = await prisma.position.findUnique({
where: { id: positionId },
include: {
interviewFlow: {
include: {
interviewFlow: {
include: {
interviewSteps: true
}
}
}
});
interviewSteps: true,
},
},
},
});

if (!positionWithInterviewFlow) {
throw new Error('Position not found');
}
if (!positionWithInterviewFlow) {
throw new Error('Position not found');
}

// Formatear la respuesta para incluir el nombre de la posición y el flujo de entrevistas
return {
positionName: positionWithInterviewFlow.title,
interviewFlow: {
id: positionWithInterviewFlow.interviewFlow.id,
description: positionWithInterviewFlow.interviewFlow.description,
interviewSteps: positionWithInterviewFlow.interviewFlow.interviewSteps.map(step => ({
id: step.id,
interviewFlowId: step.interviewFlowId,
interviewTypeId: step.interviewTypeId,
name: step.name,
orderIndex: step.orderIndex
}))
}
};
};
// Formatear la respuesta para incluir el nombre de la posición y el flujo de entrevistas
return {
positionName: positionWithInterviewFlow.title,
interviewFlow: {
id: positionWithInterviewFlow.interviewFlow.id,
description: positionWithInterviewFlow.interviewFlow.description,
interviewSteps:
positionWithInterviewFlow.interviewFlow.interviewSteps.map((step) => ({
id: step.id,
interviewFlowId: step.interviewFlowId,
interviewTypeId: step.interviewTypeId,
name: step.name,
orderIndex: step.orderIndex,
})),
applicationId: positionWithInterviewFlow.applicationDeadline,
},
};
};
58 changes: 35 additions & 23 deletions backend/src/presentation/controllers/positionController.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { Request, Response } from 'express';
import { getCandidatesByPositionService, getInterviewFlowByPositionService } from '../../application/services/positionService';
import {
getCandidatesByPositionService,
getInterviewFlowByPositionService,
} from '../../application/services/positionService';

export const getCandidatesByPosition = async (req: Request, res: Response) => {
try {
const positionId = parseInt(req.params.id);
const candidates = await getCandidatesByPositionService(positionId);
res.status(200).json(candidates);
} catch (error) {
if (error instanceof Error) {
res.status(500).json({ message: 'Error retrieving candidates', error: error.message });
} else {
res.status(500).json({ message: 'Error retrieving candidates', error: String(error) });
}
try {
const positionId = parseInt(req.params.id);
const candidates = await getCandidatesByPositionService(positionId);
res.status(200).json(candidates);
} catch (error) {
if (error instanceof Error) {
res
.status(500)
.json({ message: 'Error retrieving candidates', error: error.message });
} else {
res
.status(500)
.json({ message: 'Error retrieving candidates', error: String(error) });
}
}
};

export const getInterviewFlowByPosition = async (req: Request, res: Response) => {
try {
const positionId = parseInt(req.params.id);
const interviewFlow = await getInterviewFlowByPositionService(positionId);
res.status(200).json({ interviewFlow });
} catch (error) {
if (error instanceof Error) {
res.status(404).json({ message: 'Position not found', error: error.message });
} else {
res.status(500).json({ message: 'Server error', error: String(error) });
}
export const getInterviewFlowByPosition = async (
req: Request,
res: Response,
) => {
try {
const positionId = parseInt(req.params.id);
const interviewFlow = await getInterviewFlowByPositionService(positionId);
res.status(200).json(interviewFlow);
} catch (error) {
if (error instanceof Error) {
res
.status(404)
.json({ message: 'Position not found', error: error.message });
} else {
res.status(500).json({ message: 'Server error', error: String(error) });
}
};
}
};
85 changes: 85 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"react-bootstrap": "^2.10.2",
"react-bootstrap-icons": "^1.11.4",
"react-datepicker": "^6.9.0",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.1",
"react-scripts": "5.0.1",
Expand Down
Binary file added frontend/prompts/disen_o_ejemplo_kanban.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading