diff --git a/modules/mobileApp/routes/turnos.ts b/modules/mobileApp/routes/turnos.ts index aaae851f51..0500e1e490 100644 --- a/modules/mobileApp/routes/turnos.ts +++ b/modules/mobileApp/routes/turnos.ts @@ -64,23 +64,37 @@ router.get('/turnos', async (req: any, res, next) => { if (req.query.codificado) { matchTurno['bloques.turnos.diagnosticos.0'] = { $exists: true }; } + const matchTurnoPost = { ...matchTurno }; if (req.query.horaInicio) { - matchTurno['bloques.turnos.horaInicio'] = { $gte: new Date(req.query.horaInicio) }; + matchTurno['horaFin'] = { $gte: new Date(req.query.horaInicio) }; + matchTurnoPost['$expr'] = { + $gte: [ + { + $add: [ + '$bloques.turnos.horaInicio', + { $multiply: ['$bloques.duracionTurno', 60, 1000] } + ] + }, + new Date(req.query.horaInicio) + ] + }; } if (req.query.horaFinal) { - matchTurno['bloques.turnos.horaInicio'] = { $lt: new Date(req.query.horaFinal) }; + matchTurno['horaInicio'] = { $lt: new Date(req.query.horaFinal) }; + matchTurnoPost['bloques.turnos.horaInicio'] = { $lt: new Date(req.query.horaFinal) }; } if (req.query.tiposTurno) { matchTurno['bloques.turnos.tipoTurno'] = { $in: req.query.tiposTurno }; + matchTurnoPost['bloques.turnos.tipoTurno'] = { $in: req.query.tiposTurno }; } pipelineTurno.push({ $match: matchTurno }); pipelineTurno.push({ $unwind: '$bloques' }); pipelineTurno.push({ $unwind: '$bloques.turnos' }); - pipelineTurno.push({ $match: matchTurno }); + pipelineTurno.push({ $match: matchTurnoPost }); pipelineTurno.push({ $group: { _id: { id: '$_id', bloqueId: '$bloques._id' }, @@ -124,10 +138,12 @@ router.get('/turnos', async (req: any, res, next) => { turno.duracionTurno = elem.duracionTurno; turno.bloque_id = elem.bloque_id; turno.agenda_estado = elem.agenda_estado; + turno.webexLinks = elem.bloques.turnos.webexLinks; delete turno.updatedBy; delete turno.updatedAt; + /* Busco el turno anterior cuando fue reasignado */ const reasignado = turno.reasignado && turno.reasignado.siguiente; diff --git a/modules/webex/webex.controller.ts b/modules/webex/webex.controller.ts index b200987998..192fb250ee 100644 --- a/modules/webex/webex.controller.ts +++ b/modules/webex/webex.controller.ts @@ -6,7 +6,7 @@ const dbgWebex = debug('dbgWebex'); export async function generateWebexLinks(turno: any, agenda: any, usuario: string) { try { const params = { - idTurno: String(turno._id || turno.horaInicio), + idTurno: String(turno._id || turno.horaInicio || turno.horaFin), }; const servicio = services.get('teleconsulta');