|
|
@@ -4,6 +4,9 @@ import { MatTableDataSource } from '@angular/material/table';
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
import { InterventionService } from 'src/app/services/personal-management/intervention.service';
|
|
|
import { SpecialtyFormComponent } from './specialty-form/specialty-form.component';
|
|
|
+import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
+import { FunctionsService } from 'src/app/services/functions.service';
|
|
|
+import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-specialties-management',
|
|
|
@@ -22,6 +25,8 @@ export class SpecialtiesManagementComponent implements OnInit {
|
|
|
constructor(
|
|
|
private _interventionService: InterventionService,
|
|
|
private _dialog: MatDialog,
|
|
|
+ private _encService: EncService,
|
|
|
+ private _resourcesService: ResourcesService,
|
|
|
) {
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
@@ -38,6 +43,10 @@ export class SpecialtiesManagementComponent implements OnInit {
|
|
|
|
|
|
async getSpecialties(){
|
|
|
try{
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+
|
|
|
let idUser = localStorage.getItem('idusuario')!;
|
|
|
let specialties = await lastValueFrom(this._interventionService.getSpecialties(idUser, 1));
|
|
|
console.log(specialties);
|
|
|
@@ -83,7 +92,41 @@ export class SpecialtiesManagementComponent implements OnInit {
|
|
|
});
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(res => {
|
|
|
- console.log(res);
|
|
|
+ if(res != null && res != undefined && res != ''){
|
|
|
+ this.saveSpecialty(res, type);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ async saveSpecialty(dataEnc: string, type: string){
|
|
|
+ try{
|
|
|
+ let dataDec = await this._encService.decrypt(dataEnc);
|
|
|
+ let dataObj = JSON.parse(dataDec);
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let formData = new FormData();
|
|
|
+ let codeEnc = await this._encService.encrypt(dataObj.code);
|
|
|
+
|
|
|
+ formData.append('id_user', idUser);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('specialty_code', codeEnc);
|
|
|
+ formData.append('spacialty_name', dataObj.name);
|
|
|
+
|
|
|
+ if(type == 'new'){
|
|
|
+ await lastValueFrom(this._interventionService.registerSpecialty(formData));
|
|
|
+ this._resourcesService.openSnackBar('La especialidad se registró correctamente.');
|
|
|
+ }else{
|
|
|
+ console.log(formData);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getSpecialties();
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|