Skip to content

Commit

Permalink
RUP - Error en Adjuntos RUP (#1795)
Browse files Browse the repository at this point in the history
* fix(rup): cancelacion de solicitud para adjuntar archivo

* agrega control de registro existente antes de eliminar
  • Loading branch information
negro89 committed May 23, 2024
1 parent fcfc6b6 commit 55a06ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
19 changes: 11 additions & 8 deletions modules/mobileApp/auth_routes/rup-adjuntos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ router.post('/prestaciones-adjuntar', Auth.authenticate(), (req: any, res, next)
/**
* Borra la solicitud de adjuntar imagen cuando ya esta todo listo
*/
router.delete('/prestaciones-adjuntar/:id', Auth.authenticate(), (req: any, res, next) => {
router.delete('/prestaciones-adjuntar/:id', Auth.authenticate(), async (req: any, res, next) => {
const id = req.params.id;

PrestacionAdjunto.findById(id).then((doc: any) => {
doc.remove().then(() => {
return res.json({ status: 'ok' });
}).catch(next);
}).catch((err) => {
try {
const adjunto: any = await PrestacionAdjunto.findById(id);
if (adjunto?.id) {
adjunto.remove().then(() => {
NotificationService.solicitudAdjuntos((adjunto.profesional), id, true);
return res.json({ status: 'ok' });
});
}
} catch (err) {
return next(err);
});
}
});


Expand Down
17 changes: 11 additions & 6 deletions modules/mobileApp/controller/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,23 @@ export class NotificationService {

/**
* Envia una notificacion de adjunto
* Si cancel es true notifica la cancelacion de una solicitud previa
*/
public static solicitudAdjuntos(profesionalId, adjuntoId) {
const notificacion = {
public static solicitudAdjuntos(profesionalId, adjuntoId, cancel = false) {
const notificacion: any = {
title: 'Adjunto Andes RUP',
body: 'Tocar para ir a adjuntar un documento',
extraData: {
action: 'rup-adjuntar',
id: adjuntoId
}
};
// let id = new mongoose.Schema.Types.ObjectId(profesionalId);
// console.log(id);
if (cancel) {
notificacion.body = 'Solicitud para adjuntar documento cancelada';
notificacion.extraData.action = 'calcel-rup-adjuntar';
} else {
notificacion.body = 'Tocar para ir a adjuntar un documento';
notificacion.extraData.action = 'rup-adjuntar';

}
this.sendByProfesional(profesionalId, notificacion);
}

Expand Down

0 comments on commit 55a06ad

Please sign in to comment.