diff --git a/core/tm/routes/profesional.ts b/core/tm/routes/profesional.ts index 8ab83d99b5..aa708724aa 100644 --- a/core/tm/routes/profesional.ts +++ b/core/tm/routes/profesional.ts @@ -1077,7 +1077,25 @@ router.patch('/profesionales/:id?', Auth.authenticate(), async (req, res, next) if (resultado) { switch (req.body.op) { case 'updateNotas': - resultado.notas = req.body.data; + if (req.body.accion === 'editar') { + resultado.notas[req.body.indice].descripcion = req.body.data; + } else if (req.body.accion === 'eliminar') { + resultado.notas.splice(req.body.indice, 1); + } else { // si no es editar ni eliminar, es agregar. + // Verificamos si dentro del array hay un string vacio. + const ultimoElemento = resultado.notas[resultado.notas.length - 1]; + if (typeof ultimoElemento === 'string') { + if (ultimoElemento.length === 0) { + resultado.notas = []; + } + } + const nota = { + descripcion: req.body.data, + usuario: req.body.agente, + fecha: new Date() + }; + resultado.notas.unshift(nota); + } break; case 'updateSancion': resultado.sansiones.push(req.body.data); diff --git a/core/tm/schemas/profesional.ts b/core/tm/schemas/profesional.ts index 3364e7cbec..4666683878 100644 --- a/core/tm/schemas/profesional.ts +++ b/core/tm/schemas/profesional.ts @@ -121,7 +121,11 @@ ProfesionalSchema.add({ fecha: { type: Date, required: false }, vencimiento: { type: Date, required: false } }], - notas: [{ type: String, required: false }], + notas: [{ + usuario: { type: String, required: false }, + fecha: { type: Date, required: false }, + descripcion: { type: String, required: false }, + }], rematriculado: { type: Number, default: false }, agenteMatriculador: { type: String, required: false }, supervisor: {