-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapp.js
More file actions
90 lines (82 loc) · 1.99 KB
/
app.js
File metadata and controls
90 lines (82 loc) · 1.99 KB
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
const XLSX = require('xlsx')
const fs = require('fs')
// Ruta del archivo Excel
const filePath = 'altas_aol.xlsx'
// Cursos válidos según tipado
const validCourses = [
'AE',
'DSN',
'HP',
'Parte2',
'Parte2SSY',
'Prision',
'SSY',
'Sahaj',
'SkyCampus',
'TTC',
'VTP',
'Yes',
'premium',
'RAS',
'Eternity',
'Intuition',
'Scanning',
'Angels',
'AnxDeepSleep'
]
// Leer Excel
const workbook = XLSX.readFile(filePath)
const sheetName = workbook.SheetNames[0]
const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName])
// Función para mapear cada fila
function mapRow (row) {
// SKY (ae siempre 0)
const SKY = {
ae: 0,
long: Number(row.long || 0),
short: Number(row.short || 0)
}
// Courses
const course = {}
for (const c of validCourses) {
let val = row[c]
if (!val || String(val).trim() === '') {
val = 'no'
} else {
val = String(val).toLowerCase()
if (val !== 'si' && val !== 'no') {
val = 'no'
}
}
course[c] = val
}
return {
SKY,
email: String(row.email || '').trim(),
inactive: Boolean(row.inactive || false),
lastName: String(row.lastName || '').trim(),
name: String(row.name || '').trim(),
phone: String(row.phone || '').trim(),
placeTTC: String(row.placeTTC || '').trim(),
sign: Number(row.sign || 0),
teach_country: String(row.teach_country || '').trim(),
TTCDate: String(row.TTCDate || '').trim(),
authenticated: 1, // forzado a 1
comment: String(row.comment || '').trim(),
country: String(row.country || '').trim(),
course,
updatedAt: Date.now(),
code: String(row.code || '').trim()
}
}
// Construir objeto final
const jsonData = {}
for (const row of rows) {
const email = String(row.email || '').trim()
if (email) {
jsonData[email] = mapRow(row)
}
}
// Guardar en archivo JSON
fs.writeFileSync('users_data.json', JSON.stringify(jsonData, null, 2), 'utf8')
console.log('✅ Archivo users_data.json generado correctamente')