From 14c8790b1cc88c168828efbee91ac1561efee799 Mon Sep 17 00:00:00 2001 From: AgustinRodriguez-Andes <63318331+agustin1996ra@users.noreply.github.com> Date: Thu, 23 Apr 2026 14:56:00 -0300 Subject: [PATCH] MAT-205 MAT-206 MAT-207 --- .../profesional/profesional.component.ts | 77 ++++++++++++++++++- .../components/profesional/profesional.html | 8 ++ src/app/services/profesional.service.ts | 8 ++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/app/components/profesional/profesional.component.ts b/src/app/components/profesional/profesional.component.ts index ef4137f3d8..37fc9f2f8c 100755 --- a/src/app/components/profesional/profesional.component.ts +++ b/src/app/components/profesional/profesional.component.ts @@ -6,6 +6,7 @@ import { Component, OnInit, Input } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { Router } from '@angular/router'; import { Auth } from '@andes/auth'; +import { Plex } from '@andes/plex'; import { Observable } from 'rxjs'; @Component({ selector: 'profesionales', @@ -30,6 +31,8 @@ export class ProfesionalComponent implements OnInit { profesionalSelected: any = false; fotoProfesional: any; nuevoProfesional = false; + puedeDeshacerMatricula = false; + estadoDeshacerPorFormacion: { [formacionId: string]: any } = {}; public listado$: Observable; @@ -83,7 +86,8 @@ export class ProfesionalComponent implements OnInit { private profesionalService: ProfesionalService, public sanitizer: DomSanitizer, private router: Router, - private auth: Auth,) { } + private auth: Auth, + private plex: Plex) { } ngOnInit() { if (this.auth.getPermissions('matriculaciones:profesionales:?').length < 1) { @@ -115,6 +119,8 @@ export class ProfesionalComponent implements OnInit { seleccionarProfesional(profesional) { this.profesionalSelected = profesional; + this.puedeDeshacerMatricula = this.auth.getPermissions('matriculaciones:supervisor:aprobar').length > 0; + this.estadoDeshacerPorFormacion = {}; if (this.profesionalSelected.validadoRenaper) { this.fotoProfesional = this.sanitizer.bypassSecurityTrustResourceUrl(this.profesionalSelected.foto); } else { @@ -122,6 +128,10 @@ export class ProfesionalComponent implements OnInit { this.fotoProfesional = this.sanitizer.bypassSecurityTrustResourceUrl('data:image/jpeg;base64,' + resp); }); } + + if (this.puedeDeshacerMatricula) { + this.cargarEstadosDeshacer(); + } } routeTo(action, id) { @@ -131,4 +141,69 @@ export class ProfesionalComponent implements OnInit { cerrar() { this.profesionalSelected = false; } + + cargarEstadosDeshacer() { + const formaciones = this.profesionalSelected?.formacionGrado || []; + formaciones.forEach((formacion) => { + const formacionId = formacion?._id; + if (!formacionId || !formacion?.matriculacion?.length) { + return; + } + this.estadoDeshacerPorFormacion[formacionId] = { loading: true, canUndo: false, reason: null }; + this.profesionalService.canUndoMatriculaGrado(this.profesionalSelected.id, formacionId).subscribe( + (estado) => { + this.estadoDeshacerPorFormacion[formacionId] = { + loading: false, + canUndo: !!estado?.canUndo, + reason: estado?.reason || null + }; + }, + () => { + this.estadoDeshacerPorFormacion[formacionId] = { + loading: false, + canUndo: false, + reason: 'no se pudo verificar el estado' + }; + } + ); + }); + } + + estadoDeshacer(formacion: any) { + const formacionId = formacion?._id; + return formacionId ? this.estadoDeshacerPorFormacion[formacionId] : null; + } + + deshacerMatricula(formacion: any) { + const estado = this.estadoDeshacer(formacion); + if (!estado?.canUndo || estado?.loading) { + return; + } + const ultimaMatricula = formacion.matriculacion[formacion.matriculacion.length - 1]; + const mensaje = `${formacion.profesion?.nombre || 'Profesion'} - matrícula ${ultimaMatricula?.matriculaNumero}`; + this.plex.confirm(`¿Desea deshacer el número de matrícula?
${mensaje}`, 'Atención').then(confirmacion => { + if (!confirmacion) { + return; + } + this.profesionalService.undoMatriculaGrado(this.profesionalSelected.id, formacion._id).subscribe( + () => { + this.plex.info('success', 'Número de matrícula deshecho correctamente.'); + this.profesionalService.get({ id: this.profesionalSelected.id }).subscribe(prof => { + if (prof?.length) { + this.seleccionarProfesional(prof[0]); + } + }); + }, + (error) => { + const mensajeError = error?.error?.message || 'No fue posible deshacer la matrícula.'; + this.plex.info('warning', mensajeError); + this.profesionalService.get({ id: this.profesionalSelected.id }).subscribe(prof => { + if (prof?.length) { + this.seleccionarProfesional(prof[0]); + } + }); + } + ); + }); + } } diff --git a/src/app/components/profesional/profesional.html b/src/app/components/profesional/profesional.html index 91310160b1..4f0ce46739 100755 --- a/src/app/components/profesional/profesional.html +++ b/src/app/components/profesional/profesional.html @@ -103,6 +103,14 @@ + + diff --git a/src/app/services/profesional.service.ts b/src/app/services/profesional.service.ts index 8802a821e0..35c71d15c9 100755 --- a/src/app/services/profesional.service.ts +++ b/src/app/services/profesional.service.ts @@ -116,4 +116,12 @@ export class ProfesionalService { actualizarProfesional(body, options?: Options): Observable { return this.server.put(this.profesionalUrl + '/actualizar', body, options); } + + canUndoMatriculaGrado(profesionalId: string, formacionId: string): Observable { + return this.server.get(`${this.profesionalUrl}/${profesionalId}/formacionGrado/${formacionId}/deshacer-matricula`); + } + + undoMatriculaGrado(profesionalId: string, formacionId: string): Observable { + return this.server.post(`${this.profesionalUrl}/${profesionalId}/formacionGrado/${formacionId}/deshacer-matricula`, {}); + } }