Skip to content
Snippets Groups Projects
Commit dc4b39b4 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add id2str middleware

Middlerawre that "translates" ids in results to strings
parent 124f7fce
No related branches found
No related tags found
3 merge requests!116Release v1.0.0,!44Feature multiple where,!35Feature id2str
Pipeline #
function gender(id) {
switch(id) {
case 1:
return 'Masculino';
case 2:
return 'Feminino';
}
}
function period(id) {
switch(id) {
case 1:
return 'Diurno';
case 2:
return 'Noturno';
case 3:
return 'Integral';
default:
return 'Indefinido';
}
}
function schoolYear(id) {
switch(id) {
case 11:
return 'Creche - Menor de 1 ano';
case 12:
return 'Creche - 1 ano';
case 13:
return 'Creche - 2 anos';
case 14:
return 'Creche - 3 anos';
case 21:
return 'Pré-escola - 4 anos';
case 22:
return 'Pré-escola - 5 anos';
case 31:
return 'Ens. Fundamental - 1º Ano';
case 32:
return 'Ens. Fundamental - 1ª série/2º ano';
case 33:
return 'Ens. Fundamental - 2ª série/3º ano';
case 34:
return 'Ens. Fundamental - 3ª série/4º ano';
case 35:
return 'Ens. Fundamental - 4ª série/5º Ano';
case 41:
return 'Ens. Fundamental - 5ª série/6º ano';
case 42:
return 'Ens. Fundamental - 6ª série/7º ano';
case 43:
return 'Ens. Fundamental - 7ª série/8º ano';
case 44:
return 'Ens. Fundamental - 8ª serie/9º ano';
case 51:
return 'Ens. Médio - 1ª série'; // equivalent to 'EM 1 Série'
case 52:
return 'Ens. Médio - 2ª série'; // equivalent to 'EM 2 Série'
case 53:
return 'Ens. Médio - 3ª série'; // equivalent to 'EM 3 Série'
case 54:
return 'Ens. Médio - 4ª série'; // equivalent to 'EM 4 Série'
case 61:
return 'EJA - anos iniciais do Ens. Fundamental';
case 62:
return 'EJA - anos finais do Ens. Fundamental';
case 63:
return 'EJA - Ensino Médio';
case 64:
return 'EJA semi-presencial';
case 71:
return 'Educação Profissional';
default:
return 'Não classificado';
}
}
const ids = {
gender_id: gender,
period_id: period,
school_year_id: schoolYear
};
function transform(removeId=false) {
return (req, res, next) => {
// Para cada objeto do resultado
req.result.forEach((obj) => {
Object.keys(obj).forEach((key) => {
// Se não há uma função especificada, retorna
if(typeof ids[key] === 'undefined') return;
let id = obj[key];
obj[key.replace('_id', '_name')] = ids[key](id);
if(removeId) delete obj[key];
});
});
next();
};
}
module.exports = transform;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment