diff --git a/client/src/App.jsx b/client/src/App.jsx
index 018dfb09..c8037dc0 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -16,20 +16,29 @@ import { TeacherClass } from './components/Teacher-class/TeacherClass'
import { InfoStudent } from './components/Info-student/InfoStudent'
import { RegisterUser } from './components/Register-user/RegisterUser'
import { getPublicToken } from './api/httpRequest'
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
import { getPublicTokenFromSession } from './import/getPublicToken'
const App = () => {
+ const [loading, setLoading] = useState(true)
+
useEffect(() => {
const publicToken = getPublicTokenFromSession()
if (!publicToken) {
getAndSavePublicToken()
+ } else {
+ setLoading(false)
}
}, [])
const getAndSavePublicToken = async () => {
const response = await getPublicToken()
sessionStorage.setItem('public-token', response)
+ setLoading(false)
+ }
+
+ if (loading) {
+ return
Terminando de configurar algunos ajustes...
}
return (
diff --git a/client/src/ProtectedRoute.jsx b/client/src/ProtectedRoute.jsx
index be4612e0..94366c52 100644
--- a/client/src/ProtectedRoute.jsx
+++ b/client/src/ProtectedRoute.jsx
@@ -1,6 +1,7 @@
import Cookies from 'js-cookie'
import { isExpired } from 'react-jwt'
import { Navigate, useLocation } from 'react-router-dom'
+import { getPublicTokenFromSession } from './import/getPublicToken'
export const ProtectedRoute = ({ redirectTo, children }) => {
const location = useLocation()
@@ -22,7 +23,8 @@ export const IsLogged = ({ redirectTo, children }) => {
const idRol = localStorage.getItem('idRol')
const token = Cookies.get('token')
- const publicToken = sessionStorage.getItem('public-token')
+ const publicToken = getPublicTokenFromSession()
+
const isExpiredToken = token ? isExpired(token) : true
const isExpiredPublicToken = publicToken ? isExpired(publicToken) : true
diff --git a/client/src/api/httpRequest.jsx b/client/src/api/httpRequest.jsx
index c15fdf10..1aa8387b 100644
--- a/client/src/api/httpRequest.jsx
+++ b/client/src/api/httpRequest.jsx
@@ -3,16 +3,17 @@ import { getPublicTokenFromSession } from '../import/getPublicToken'
const baseUrl = 'http://localhost:3000'
const api = '/api'
-const publicToken = getPublicTokenFromSession()
export const getPublicToken = async () => {
const URL = `${baseUrl}${api}/v1/public/token/generate`
+ const publicToken = getPublicTokenFromSession()
const { data } = await axios.get(URL, { headers: { Authorization: publicToken } })
return data
}
export const getStudentsByTeacherId = async (id) => {
const URL = `${baseUrl}${api}/v1/detailInfoStudents/teacher/${id}`
+ const publicToken = getPublicTokenFromSession()
const { data } = await axios.get(URL, { headers: { Authorization: publicToken } })
return data
}
@@ -20,6 +21,7 @@ export const getStudentsByTeacherId = async (id) => {
/* LOGIN */
export const Login = async (data) => {
const URL = `${baseUrl}${api}/v1/login`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.post(URL, data, { headers: { Authorization: publicToken } })
return response
@@ -28,6 +30,7 @@ export const Login = async (data) => {
/* OBTENER APRENDICES */
export const GetUsersHttp = async () => {
const URL = `${baseUrl}${api}/v1/students`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -35,6 +38,7 @@ export const GetUsersHttp = async () => {
export const GetStudentsDetailById = async (userID) => {
const URL = `${baseUrl}${api}/v1/detailInfoStudent/${userID}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -43,6 +47,7 @@ export const GetStudentsDetailById = async (userID) => {
/* INSCRIBIR APRENDICES */
export const InscriptionApprentice = async (data) => {
const URL = `${baseUrl}${api}/v1/create-inscriptions`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.post(URL, data, { headers: { Authorization: publicToken } })
return response
@@ -51,6 +56,7 @@ export const InscriptionApprentice = async (data) => {
/* BUSCAR APRENDICES POR NOMBRE */
export const GetUserByName = async (searchQuery) => {
const URL = `${baseUrl}${api}/v1/studentName?nombreCompleto=${searchQuery}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -58,6 +64,7 @@ export const GetUserByName = async (searchQuery) => {
/* BUSCAR APRENDICES DE UNA FICHA */
export const GetStudentsByCourse = async (data) => {
const URL = `${baseUrl}${api}/v1/classStudents?numero_ficha=${data}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
}
@@ -65,6 +72,7 @@ export const GetStudentsByCourse = async (data) => {
/* BUSCAR INSTRUCTOR POR NOMBRE */
export const GetTeacherByName = async (data) => {
const URL = `${baseUrl}${api}/v1/teacherName?nombreCompleto=${data}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
}
@@ -72,6 +80,7 @@ export const GetTeacherByName = async (data) => {
// OBTENER FICHA POR NUMERO DE FICHA
export const GetClassByNumber = async (data) => {
const URL = `${baseUrl}${api}/v1/classNumber?numero_ficha=${data}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -79,6 +88,7 @@ export const GetClassByNumber = async (data) => {
export const sendEmailFunctions = async (data) => {
const URL = `${baseUrl}${api}/v1/sendEmail/functions`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.post(URL, data, { headers: { Authorization: publicToken } })
return response
@@ -86,6 +96,7 @@ export const sendEmailFunctions = async (data) => {
export const detailInfoStudents = async () => {
const URL = `${baseUrl}${api}/v1/detailInfoStudents`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -94,6 +105,7 @@ export const detailInfoStudents = async () => {
// OBTENER REGISTROS
export const getInscriptions = async () => {
const URL = `${baseUrl}${api}/v1/inscriptions`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -101,6 +113,7 @@ export const getInscriptions = async () => {
export const getInscriptionsByTeacherId = async (id) => {
const URL = `${baseUrl}${api}/v1/inscriptions/teacher/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response.data
@@ -109,6 +122,7 @@ export const getInscriptionsByTeacherId = async (id) => {
// OBTENER REGISTRO POR ID
export const getInscriptionById = async (id) => {
const URL = `${baseUrl}${api}/v1/inscription/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -117,6 +131,7 @@ export const getInscriptionById = async (id) => {
// OBTENER DETALLES INSCRIPCION BY ID
export const getInscriptionDetails = async (id, limit = 4, offset = 0) => {
const URL = `${baseUrl}${api}/v1/inscriptionDetails/${id}?limit=${limit}&offset=${offset}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -125,6 +140,7 @@ export const getInscriptionDetails = async (id, limit = 4, offset = 0) => {
// OBTENER DETALLES INSCRIPCION POR USUARIO
export const inscriptionDetailUser = async (id, limit = 3, offset = 0) => {
const URL = `${baseUrl}${api}/v1/inscriptionDetailsUser/${id}?limit=${limit}&offset=${offset}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -133,6 +149,7 @@ export const inscriptionDetailUser = async (id, limit = 3, offset = 0) => {
// MODIFICAR DETALLES DE LA INSCRIPCION
export const inscriptionDetailsUpdate = async (id, payload) => {
const URL = `${baseUrl}${api}/v1/update-inscription-detail/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
return response
@@ -140,6 +157,7 @@ export const inscriptionDetailsUpdate = async (id, payload) => {
export const readExcel = async (fileData) => {
const URL = `${baseUrl}${api}/v1/inscription-excel-file`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.post(URL, fileData, {
headers: {
'Content-Type': 'multipart/form-data',
@@ -152,6 +170,7 @@ export const readExcel = async (fileData) => {
// OBTENER FICHAS
export const getClass = async () => {
const URL = `${baseUrl}${api}/v1/classes`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
}
@@ -159,6 +178,7 @@ export const getClass = async () => {
// OBTENER FICHAS POR ID
export const getClassById = async (id) => {
const URL = `${baseUrl}${api}/v1/class/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -167,6 +187,7 @@ export const getClassById = async (id) => {
// OBTENER INSTRUCTORES
export const getTeachers = async (limit = 50) => {
const URL = `${baseUrl}${api}/v1/teachers?limit=${limit}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -175,6 +196,7 @@ export const getTeachers = async (limit = 50) => {
// OBTENER FICHAS POR ID INSTRUCTOR
export const getClassByTeacherId = async (id) => {
const URL = `${baseUrl}${api}/v1/teacherClasses/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -183,6 +205,7 @@ export const getClassByTeacherId = async (id) => {
// OBTENER FICHAS SIN INSTRUCTOR LIDER O SEGUIMIENTO
export const getClassFree = async () => {
const URL = `${baseUrl}${api}/v1/classesFree`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -191,6 +214,7 @@ export const getClassFree = async () => {
// OBTENER AVAL POR ID
export const getAvalById = async (id) => {
const URL = `${baseUrl}${api}/v1/inscriptionDetail/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -199,6 +223,7 @@ export const getAvalById = async (id) => {
// OBTENER USERS BY ID
export const getUserById = async (id) => {
const URL = `${baseUrl}${api}/v1/user/${id}`
+ const publicToken = getPublicTokenFromSession()
try {
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
@@ -210,6 +235,7 @@ export const getUserById = async (id) => {
export const sendEmail = async (payload) => {
const URL = `${baseUrl}${api}/v1/sendEmail`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.post(URL, payload, { headers: { Authorization: publicToken } })
return response
}
@@ -217,6 +243,7 @@ export const sendEmail = async (payload) => {
// MODIFICAR INSTRUCTOR SEGUIMIENTO DE UNA FICHA
export const updateTeacherSeguimiento = async (numero_ficha, payload) => {
const URL = `${baseUrl}${api}/v1/teacherClass?numero_ficha=${numero_ficha}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.patch(URL, { id_instructor_seguimiento: payload }, { headers: { Authorization: publicToken } })
return response
@@ -225,6 +252,7 @@ export const updateTeacherSeguimiento = async (numero_ficha, payload) => {
// MODIFICAR INSTRUCTOR LIDER DE UNA FICHA
export const updateTeacherLider = async (numero_ficha, payload) => {
const URL = `${baseUrl}${api}/v1/teacherLiderClass?numero_ficha=${numero_ficha}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.patch(URL, { id_instructor_lider: payload }, { headers: { Authorization: publicToken } })
return response
@@ -233,6 +261,7 @@ export const updateTeacherLider = async (numero_ficha, payload) => {
// OBTENER FICHAS POR ID INSTRUCTOR
export const getClassByLiderTeacherId = async (id) => {
const URL = `${baseUrl}${api}/v1/teacherLiderClasses/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -242,6 +271,7 @@ export const getClassByLiderTeacherId = async (id) => {
export const getModalitiesById = async (id) => {
const URL = `${baseUrl}${api}/v1/practical-stages/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
}
@@ -249,32 +279,38 @@ export const getModalitiesById = async (id) => {
// Obtener inscripcion por nombre
export const GetInscriptionByName = async (data) => {
const URL = `${baseUrl}${api}/v1/inscriptionName?nombreCompleto=${data}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
}
export const createCourse = async (data) => {
const URL = `${baseUrl}${api}/v1/class`
+ const publicToken = getPublicTokenFromSession()
return await axios.post(URL, data, { headers: { Authorization: publicToken } })
}
export const createStudent = async (data) => {
const URL = `${baseUrl}${api}/v1/create-students`
+ const publicToken = getPublicTokenFromSession()
return await axios.post(URL, data, { headers: { Authorization: publicToken } })
}
export const registerUser = async (payload) => {
const URL = `${baseUrl}${api}/v1/register`
+ const publicToken = getPublicTokenFromSession()
return await axios.post(URL, payload, { headers: { Authorization: publicToken } })
}
export const getInfoTeacherByID = async (id) => {
const URL = `${baseUrl}${api}/v1/teacher/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
/* Edit User */
export const EditUser = async (id, payload) => {
const URL = `${baseUrl}${api}/v1/edit-user/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
return response
@@ -282,61 +318,73 @@ export const EditUser = async (id, payload) => {
export const getCoordinators = async () => {
const URL = `${baseUrl}${api}/v1/coordinators`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
export const getCoordinatorNameByID = async (id) => {
const URL = `${baseUrl}${api}/v1/coordinator/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
export const getLettersByStudentID = async (id) => {
const URL = `${baseUrl}${api}/v1/getLetterByStudent/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
export const patchLetterByID = async (id, payload) => {
const URL = `${baseUrl}${api}/v1/modifyLetter/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
}
export const getBitacorasByStudentId = async (id) => {
const URL = `${baseUrl}${api}/v1/getBitacorasByStudent/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
export const patchBitacoraById = async (id, payload) => {
const URL = `${baseUrl}${api}/v1/modifyBitacora/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
}
export const patchVisitById = async (id, payload) => {
const URL = `${baseUrl}${api}/v1/modifyVisit/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
}
export const getVisitsByStudent = async (id) => {
const URL = `${baseUrl}${api}/v1/getVisitsByStudent/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
export const getVisitDataById = async (id) => {
const URL = `${baseUrl}${api}/v1/getVisitData/${id}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, { headers: { Authorization: publicToken } })
}
export const sendExcelContrato = async (payload) => {
const URL = `${baseUrl}${api}/v1/read-excel-file/students`
+ const publicToken = getPublicTokenFromSession()
return await axios.post(URL, payload, { headers: { Authorization: publicToken } })
}
export const sendExcelCourse = async (payload) => {
const URL = `${baseUrl}${api}/v1/read-excel-file/classes`
+ const publicToken = getPublicTokenFromSession()
return await axios.post(URL, payload, { headers: { Authorization: publicToken } })
}
export const generateExcelClass = async (classNumber) => {
const URL = `${baseUrl}${api}/v1/create-excel-class`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, {
params: {
numero_ficha: classNumber
@@ -348,6 +396,7 @@ export const generateExcelClass = async (classNumber) => {
export const generateExcelStudents = async () => {
const URL = `${baseUrl}${api}/v1/create-excel-students`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, {
headers: { Authorization: publicToken },
responseType: 'arraybuffer'
@@ -356,12 +405,14 @@ export const generateExcelStudents = async () => {
export const createVisit = async (payload) => {
const URL = `${baseUrl}${api}/v1/create-visit`
+ const publicToken = getPublicTokenFromSession()
return await axios.post(URL, payload, { headers: { Authorization: publicToken } })
}
/* OBTENER ESTADO DE APRENDICES */
export const getStudentState = async (id) => {
const URL = `${baseUrl}${api}/v1/studentState/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -370,6 +421,7 @@ export const getStudentState = async (id) => {
/* EDITAR ESTADO DE APRENDICES */
export const editStudentState = async (id, payload) => {
const URL = `${baseUrl}${api}/v1/update-student-state/${id}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
return response
@@ -377,6 +429,7 @@ export const editStudentState = async (id, payload) => {
export const editDateClass = async (payload) => {
const URL = `${baseUrl}${api}/v1/dateClass`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.patch(URL, payload, { headers: { Authorization: publicToken } })
return response
@@ -385,6 +438,7 @@ export const editDateClass = async (payload) => {
// OBTENER FICHAS SIN INSTRUCTOR POR NUMERO DE FICHA
export const GetClassFreeByNumber = async (data) => {
const URL = `${baseUrl}${api}/v1/classFreeNumber?numero_ficha=${data}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
@@ -393,6 +447,7 @@ export const GetClassFreeByNumber = async (data) => {
// Generar excel de todos los aprendices en prácticas
export const generateExcelStudentsPractical = async () => {
const URL = `${baseUrl}${api}/v1/create-excel-students-practical`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, {
headers: { Authorization: publicToken },
responseType: 'arraybuffer'
@@ -402,6 +457,7 @@ export const generateExcelStudentsPractical = async () => {
// Generar excel de todos los aprendices sin prácticas
export const generateExcelStudentsNoPractical = async () => {
const URL = `${baseUrl}${api}/v1/create-excel-students-nopractical`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, {
headers: { Authorization: publicToken },
responseType: 'arraybuffer'
@@ -410,6 +466,7 @@ export const generateExcelStudentsNoPractical = async () => {
// Generar excel por modalidad
export const generateExcelStudentsByModality = async (modality) => {
const URL = `${baseUrl}${api}/v1/create-excel-students-category?modality=${modality}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, {
headers: { Authorization: publicToken },
responseType: 'arraybuffer'
@@ -419,6 +476,7 @@ export const generateExcelStudentsByModality = async (modality) => {
// Generar excel de estudiantes por instructor
export const generateExcelStudentsByInstructor = async (teacherName) => {
const URL = `${baseUrl}${api}/v1/create-excel-students-instructor?instructor=${teacherName}`
+ const publicToken = getPublicTokenFromSession()
return await axios.get(URL, {
headers: { Authorization: publicToken },
responseType: 'arraybuffer'
@@ -427,6 +485,7 @@ export const generateExcelStudentsByInstructor = async (teacherName) => {
export const getClassTeacherByClassNumber = async (id, data) => {
const URL = `${baseUrl}${api}/v1/classTeacherNumber/${id}?numero_ficha=${data}`
+ const publicToken = getPublicTokenFromSession()
const response = await axios.get(URL, { headers: { Authorization: publicToken } })
return response
diff --git a/client/src/components/Register-list/RegisterList.jsx b/client/src/components/Register-list/RegisterList.jsx
index 3b777d5d..ef24cdff 100644
--- a/client/src/components/Register-list/RegisterList.jsx
+++ b/client/src/components/Register-list/RegisterList.jsx
@@ -265,8 +265,8 @@ export const RegisterList = () => {
*/
const getRegistros = async () => {
const { id_rol, id_usuario } = getUserID().user
- if (String(id_rol) === '3') {
- getRegistersTrackingInstructor(id_usuario)
+ if (String(id_rol) === '3' || String(id_rol) === '2') {
+ getRegistersTrackingInstructorOrCoordinator(id_usuario)
return
}
try {
@@ -295,7 +295,7 @@ export const RegisterList = () => {
}
}
- const getRegistersTrackingInstructor = async (id) => {
+ const getRegistersTrackingInstructorOrCoordinator = async (id) => {
try {
const response = await getInscriptionsByTeacherId(id)
const { data } = response
diff --git a/server/src/controllers/inscriptions.controllers.ts b/server/src/controllers/inscriptions.controllers.ts
index ae44490f..468d28eb 100644
--- a/server/src/controllers/inscriptions.controllers.ts
+++ b/server/src/controllers/inscriptions.controllers.ts
@@ -22,10 +22,10 @@ export const getInscriptions = async (_req: Request, res: Response): Promise => {
+export const getInscriptionsByTeacherOrCoordinatorId = async (req: Request, res: Response): Promise => {
const { id } = req.params
try {
- const [inscriptions] = await connection.query('SELECT i.*, m.nombre_modalidad, COUNT(d.estado_aval) AS avales_aprobados FROM inscripciones i INNER JOIN modalidades m ON i.modalidad_inscripcion = m.id_modalidad INNER JOIN detalles_inscripciones d ON i.id_inscripcion = d.id_inscripcion AND d.responsable_aval = 4 GROUP BY i.id_inscripcion ORDER BY CASE WHEN i.estado_general_inscripcion = "Pendiente" THEN 0 WHEN i.estado_general_inscripcion = "Aprobado" THEN 1 WHEN i.estado_general_inscripcion = "Rechazado" THEN 2 END , i.fecha_creacion DESC', [id])
+ const [inscriptions] = await connection.query('SELECT i.*, m.nombre_modalidad, COUNT(d.estado_aval) AS avales_aprobados FROM inscripciones i INNER JOIN modalidades m ON i.modalidad_inscripcion = m.id_modalidad INNER JOIN detalles_inscripciones d ON i.id_inscripcion = d.id_inscripcion AND d.responsable_aval = ? GROUP BY i.id_inscripcion ORDER BY CASE WHEN i.estado_general_inscripcion = "Pendiente" THEN 0 WHEN i.estado_general_inscripcion = "Aprobado" THEN 1 WHEN i.estado_general_inscripcion = "Rechazado" THEN 2 END , i.fecha_creacion DESC', [id])
return res.status(httpStatus.OK).json({ data: inscriptions })
} catch (error) {
return handleHTTP(res, error as CustomError)
diff --git a/server/src/routes/inscriptions.routes.ts b/server/src/routes/inscriptions.routes.ts
index 88eb5c91..d1555545 100644
--- a/server/src/routes/inscriptions.routes.ts
+++ b/server/src/routes/inscriptions.routes.ts
@@ -1,5 +1,5 @@
import { type IRouter, Router } from 'express'
-import { createInscriptions, editInscription, editInscriptionDetail, getInscriptionById, getInscriptions, getInscriptionsDetailsById, getInscriptionsDetailsByInscription, getInscriptionsDetailsByUser, returnExcelData, getInscriptionsDetailsByName, getInscriptionsByTeacherId } from '../controllers/inscriptions.controllers.js'
+import { createInscriptions, editInscription, editInscriptionDetail, getInscriptionById, getInscriptions, getInscriptionsDetailsById, getInscriptionsDetailsByInscription, getInscriptionsDetailsByUser, returnExcelData, getInscriptionsDetailsByName, getInscriptionsByTeacherOrCoordinatorId } from '../controllers/inscriptions.controllers.js'
import { checkIdReq } from '../middlewares/idCheck.middlewares.js'
import { checkInscriptionData, checkInscriptionDetailData, configureMulterExcel, readExcelFile } from '../middlewares/inscriptions.middlewares.js'
import { checkName } from '../middlewares/users.middlewares.js'
@@ -21,14 +21,14 @@ const inscriptionRoutes: IRouter = Router()
inscriptionRoutes.get('/v1/inscriptions', getInscriptions)
/**
- * Obtiene todas las incripciones relacionadas a un instructor de seguimiento
+ * Obtiene todas las incripciones relacionadas a un instructor de seguimiento o coordinador
* @route GET /v1/inscriptions/teacher/:id
* @param {string} request.param.id
* @returns {Promise>}
* @returns {Error} HTTP Status - Error en el request
* @async
*/
-inscriptionRoutes.get('/v1/inscriptions/teacher/:id', checkIdReq, getInscriptionsByTeacherId)
+inscriptionRoutes.get('/v1/inscriptions/teacher/:id', checkIdReq, getInscriptionsByTeacherOrCoordinatorId)
/**
* Obtener una inscripción por su ID.