Skip to content
Snippets Groups Projects
id2str.js 2.83 KiB
Newer Older
Vytor Calixto's avatar
Vytor Calixto committed
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,
    gender,
    period,
    schoolYear
};