Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;