Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions profesional_sisa/controller/ejecutaConsulta.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { postProfesionalSISA, crearProfesionalSISA } from '../service/operaciones.service';
import { postProfesionalSISA, crearProfesionalSISA, patchProfesional } from '../service/operaciones.service';


export async function exportSISA(profesional) {
let postsSISA = [];

if (isMatriculado(profesional)) {
let formacionesGrado = profesional.formacionGrado.filter(async e => e.matriculado);
for (let formacionGrado of formacionesGrado) {
Expand All @@ -12,7 +11,24 @@ export async function exportSISA(profesional) {
}
}

return await Promise.all(postsSISA);
return await Promise.all(postsSISA)
.then(async resultados => {
for (let i = 0; i < resultados.length; i++) {
if (resultados[i]?.idProfesional) {
profesional.formacionGrado[i].configuracionSisa = {
idProfesional: resultados[i].idProfesional,
idProfesion: resultados[i].idProfesion,
idMatricula: resultados[i].idMatricula,
codigoProfesional: resultados[i].codigoProfesional
}
}
}
await patchProfesional(profesional.id, profesional.formacionGrado);
return resultados;
})
.catch(error => {
console.error("Una de las promesas falló:", error);
});
}

function isMatriculado(profesional) {
Expand Down
46 changes: 41 additions & 5 deletions profesional_sisa/service/operaciones.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export async function postProfesionalSISA(profesional: any) {
json: true,
};
const resJson = await handleHttpRequest(options);

if (resJson && resJson.length > 0) {
const statusCode = resJson[0];
const body = resJson[1];
Expand All @@ -33,7 +32,6 @@ export async function postProfesionalSISA(profesional: any) {

export async function getProfesional(idProfesional) {
const url = `${ANDES_HOST}/core/tm/profesionales/${idProfesional}`;
//${ANDES_KEY}
const options = {
uri: url,
method: 'GET',
Expand Down Expand Up @@ -129,7 +127,6 @@ export async function crearProfesionalSISA(profesional, formacionGrado) {
domicilio: {}
}
}

};
profesionalSisa['profesional']['apellido'] = profesional.apellido;
profesionalSisa['profesional']['nombre'] = profesional.nombre;
Expand All @@ -138,12 +135,13 @@ export async function crearProfesionalSISA(profesional, formacionGrado) {
profesionalSisa['profesional']['sexo'] = (profesional.sexo === 'femenino' || profesional.sexo === 'Femenino') ? 'F' : (profesional.sexo === 'masculino' || profesional.sexo === 'Masculino') ? 'M' : 'X';
profesionalSisa['profesional']['fechaNacimiento'] = moment(profesional.fechaNacimiento).format('DD-MM-YYYY');
const email = profesional.contactos.find(x => x.tipo === 'email' && x.valor);
profesionalSisa['profesional']['email'] = email ? email.valor : '';
if (validarEmail(email.valor)) {
profesionalSisa['profesional']['email'] = email.valor;
}
profesionalSisa['profesional']['idPaisNacimiento'] = 200;
profesionalSisa['profesional']['idPais'] = 200;
profesionalSisa['profesional']['habilitado'] = 'SI';
profesionalSisa['profesion']['titulo'] = formacionGrado ? formacionGrado.titulo : '';

profesionalSisa['profesion']['fechaTitulo'] = moment(formacionGrado.fechaEgreso).format('DD-MM-YYYY');

let profesionDeReferencia: any = await getProfesion(formacionGrado.profesion.codigo);
Expand Down Expand Up @@ -192,4 +190,42 @@ export async function crearProfesionalSISA(profesional, formacionGrado) {

});
return profesionalSisa;
}

export async function patchProfesional(id, cambios) {
const body = {
op: 'upConfigSIISA',
data: cambios
}
const url = `${ANDES_HOST}/core/tm/profesionales/${id}`;
const options = {
uri: url,
method: 'PATCH',
headers: { Authorization: `JWT ${ANDES_KEY}`, 'Content-Type': 'application/json' },
body,
json: true,
};
try {
const resJson = await handleHttpRequest(options);
if (resJson && resJson.length > 0) {
const statusCode = resJson[0];
const body = resJson[1];
if (statusCode >= 200 && statusCode < 300 && body?.resultado != 'ERROR_DATOS') {
return body;
} else {
log.error('profesional_sisa:getProfesional', { options, body }, 'unkown error', userScheduler);
return null;
}
} else {
log.error('profesional_sisa:getProfesional', { options }, 'unkown error', userScheduler);
return null;
}
} catch (error) {
log.error('profesional_sisa:getProfesional', { error, url }, error.message, userScheduler);
}
}

function validarEmail(email) {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}