2020-10-01 16:20:56 -05:00
|
|
|
const colors = require('colors')
|
|
|
|
|
const { Op } = require('sequelize')
|
|
|
|
|
const csv = require('csv-parser')
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const Carrito = require('./tables/Carrito')
|
|
|
|
|
const Carrera = require('./tables/Carrera')
|
|
|
|
|
const CarreraPlantel = require('./tables/CarreraPlantel')
|
|
|
|
|
const Plantel = require('./tables/Plantel')
|
|
|
|
|
const Equipo = require('./tables/Equipo')
|
|
|
|
|
const Horario = require('./tables/Horario')
|
|
|
|
|
const Mesa = require('./tables/Mesa')
|
|
|
|
|
const Parte = require('./tables/Parte')
|
|
|
|
|
const Salon = require('./tables/Salon')
|
|
|
|
|
const Status = require('./tables/Status')
|
|
|
|
|
const TipoCarrito = require('./tables/TipoCarrito')
|
|
|
|
|
const TipoMulta = require('./tables/TipoMulta')
|
|
|
|
|
const TipoOperador = require('./tables/TipoOperador')
|
|
|
|
|
const TipoUsuario = require('./tables/TipoUsuario')
|
|
|
|
|
|
|
|
|
|
const dataTipoCarrito = async () => {
|
2020-10-05 00:19:29 -05:00
|
|
|
const data = ['Chromebook', 'iPad', 'Laptop']
|
2020-10-01 16:20:56 -05:00
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo tipo_carrito'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el registro ${data[i]}`.magenta)
|
|
|
|
|
await TipoCarrito.create({ nombre: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataTipoMulta = async () => {
|
|
|
|
|
const data = ['Servicio', 'Red']
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo tipo_Multa'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el registro ${data[i]}`.magenta)
|
|
|
|
|
await TipoMulta.create({ nombre: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataTipoOperador = async () => {
|
|
|
|
|
const data = ['admin', 'operador']
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo tipo_operador'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el registro ${data[i]}`.magenta)
|
|
|
|
|
await TipoOperador.create({ nombre: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataTipoUsuario = async () => {
|
|
|
|
|
const data = [
|
|
|
|
|
'alumno_interno',
|
|
|
|
|
'alumno_externo',
|
|
|
|
|
'profesor_interno',
|
|
|
|
|
'profesor_externo',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo tipo_usuario'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el registro ${data[i]}`.magenta)
|
|
|
|
|
await TipoUsuario.create({ nombre: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataStatus = async () => {
|
|
|
|
|
const data = ['Activo', 'Cargando', 'Mantenimiento', 'Dañado', 'Perdida']
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo Status'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el registro ${data[i]}`.magenta)
|
|
|
|
|
await Status.create({ status: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataMesa = async () => {
|
|
|
|
|
console.log('\nInstalando catalogo Mesa'.bold.blue)
|
|
|
|
|
for (let i = 1; i <= 150; i++) {
|
|
|
|
|
console.log(`Se ha creado la mesa ${i}`.magenta)
|
|
|
|
|
await Mesa.create({})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataSalon = async () => {
|
|
|
|
|
const data = [
|
|
|
|
|
'San Luis Potosí',
|
|
|
|
|
'Sinaloa',
|
|
|
|
|
'Sonora',
|
|
|
|
|
'Tabasco',
|
|
|
|
|
'Tamaulipas',
|
|
|
|
|
'Tlaxcala',
|
|
|
|
|
'Veracruz',
|
|
|
|
|
'Yucatán',
|
|
|
|
|
'Zacatecas',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo Salon'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el Salon ${data[i]}`.magenta)
|
|
|
|
|
await Salon.create({ salon: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataHorario = async () => {
|
|
|
|
|
const data = [
|
|
|
|
|
'8:00-10:00',
|
|
|
|
|
'10:00-12:00',
|
|
|
|
|
'12:00-14:00',
|
|
|
|
|
'14:00-16:00',
|
|
|
|
|
'16:00-18:00',
|
|
|
|
|
'18:00-20:00',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo Horario'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
console.log(`Se ha creado el Horario ${data[i]}`.magenta)
|
|
|
|
|
await Horario.create({ horario: data[i] })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const csvJson = (filepath) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let data = []
|
|
|
|
|
|
|
|
|
|
fs.createReadStream(filepath)
|
|
|
|
|
.on('error', (error) => reject(error))
|
|
|
|
|
.pipe(csv())
|
|
|
|
|
.on('data', (row) => data.push(row))
|
|
|
|
|
.on('end', () => resolve(data))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataCarrera = async () => {
|
2020-10-02 00:47:54 -05:00
|
|
|
const data = await csvJson('./csv/carrera.csv')
|
2020-10-01 16:20:56 -05:00
|
|
|
.then((res) => res)
|
|
|
|
|
.catch((err) => console.log(err))
|
|
|
|
|
|
2020-10-01 23:58:20 -05:00
|
|
|
console.log('\nInstalando catalogo Carrera'.bold.blue)
|
2020-10-01 16:20:56 -05:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
await Carrera.findOne({ where: { idCarrera: Number(data[i].clave) } })
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res) {
|
|
|
|
|
console.log(`Se ha creado la Carrera ${data[i].carrera}`.magenta)
|
|
|
|
|
await Carrera.create({
|
|
|
|
|
idCarrera: Number(data[i].clave),
|
|
|
|
|
carrera: data[i].carrera,
|
|
|
|
|
nivel: data[i].nivel,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataPlantel = async () => {
|
2020-10-02 00:47:54 -05:00
|
|
|
const data = await csvJson('./csv/plantel.csv')
|
2020-10-01 16:20:56 -05:00
|
|
|
.then((res) => res)
|
|
|
|
|
.catch((err) => console.log(err))
|
|
|
|
|
|
2020-10-01 23:58:20 -05:00
|
|
|
console.log('\nInstalando catalogo Plantel'.bold.blue)
|
2020-10-01 16:20:56 -05:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
await Plantel.findOne({ where: { idPlantel: Number(data[i].cve_plantel) } })
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res) {
|
|
|
|
|
console.log(
|
|
|
|
|
`Se ha creado el Plantel ${data[i].nombre_plantel}`.magenta
|
|
|
|
|
)
|
|
|
|
|
await Plantel.create({
|
|
|
|
|
idPlantel: Number(data[i].cve_plantel),
|
|
|
|
|
plantel: data[i].nombre_plantel,
|
|
|
|
|
})
|
|
|
|
|
} else console.log('Repetido')
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dataCarreraPlantel = async () => {
|
2020-10-02 00:47:54 -05:00
|
|
|
const data = await csvJson('./csv/carrera_plantel.csv')
|
2020-10-01 16:20:56 -05:00
|
|
|
.then((res) => res)
|
|
|
|
|
.catch((err) => console.log(err))
|
|
|
|
|
|
2020-10-01 23:58:20 -05:00
|
|
|
console.log('\nInstalando catalogo CarreraPlantel'.bold.blue)
|
2020-10-01 16:20:56 -05:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
await CarreraPlantel.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
[Op.and]: [
|
|
|
|
|
{ idPlantel: Number(data[i].plantel) },
|
|
|
|
|
{ idCarrera: Number(data[i].carrera) },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
if (!res) {
|
|
|
|
|
console.log(
|
|
|
|
|
`Se ha creado la CarreraPlantel con carrera ${data[i].carrera} y plantel ${data[i].plantel}`
|
|
|
|
|
.magenta
|
|
|
|
|
)
|
|
|
|
|
await CarreraPlantel.create({
|
|
|
|
|
idCarrera: data[i].carrera,
|
|
|
|
|
idPlantel: data[i].plantel,
|
|
|
|
|
})
|
|
|
|
|
} else console.log('Repetido')
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 23:58:20 -05:00
|
|
|
const dataEquipo = async () => {
|
2020-10-02 00:47:54 -05:00
|
|
|
const data = await csvJson('./csv/CARGA-MASIVA-CEMM.csv')
|
2020-10-01 23:58:20 -05:00
|
|
|
.then((res) => res)
|
|
|
|
|
.catch((err) => console.log(err))
|
|
|
|
|
|
|
|
|
|
console.log('\nInstalando catalogo Equipo'.bold.blue)
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
let tipo
|
|
|
|
|
|
|
|
|
|
if (data[i].Tipo === 'CHROMEBOOK') tipo = 1
|
|
|
|
|
else if (data[i].Tipo === 'LAPTOP') tipo = 3
|
|
|
|
|
|
|
|
|
|
await Carrito.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
[Op.and]: [{ sobrenombre: data[i].Carrito }, { idTipoCarrito: tipo }],
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
let idCarrito
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
console.log(
|
|
|
|
|
`\nSe ha creado el Carrito ${data[i].Carrito} de tipo ${data[i].Tipo}`
|
|
|
|
|
.magenta
|
|
|
|
|
)
|
|
|
|
|
await Carrito.create({
|
|
|
|
|
sobrenombre: data[i].Carrito,
|
|
|
|
|
kiosko: 1,
|
|
|
|
|
idTipoCarrito: tipo,
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
idCarrito = res.idCarrito
|
|
|
|
|
})
|
|
|
|
|
} else idCarrito = res.idCarrito
|
|
|
|
|
console.log(
|
|
|
|
|
`Se ha creado el Equipo con noSerie ${data[i].NoSerie} noInventario ${data[i].NoInventario} sobrenombre ${data[i].Sobrenombre}`
|
|
|
|
|
.magenta
|
|
|
|
|
)
|
|
|
|
|
await Equipo.create({
|
|
|
|
|
noSerie: data[i].NoSerie,
|
|
|
|
|
noInventario: data[i].NoInventario,
|
|
|
|
|
sobrenombre: data[i].Sobrenombre,
|
|
|
|
|
idCarrito: idCarrito,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-01 16:20:56 -05:00
|
|
|
// Parte
|
|
|
|
|
|
|
|
|
|
const install = async () => {
|
|
|
|
|
await dataTipoCarrito()
|
|
|
|
|
await dataTipoMulta()
|
|
|
|
|
await dataTipoUsuario()
|
|
|
|
|
await dataTipoOperador()
|
|
|
|
|
await dataStatus()
|
|
|
|
|
await dataMesa()
|
|
|
|
|
await dataSalon()
|
|
|
|
|
await dataHorario()
|
|
|
|
|
|
|
|
|
|
await dataCarrera()
|
|
|
|
|
await dataPlantel()
|
|
|
|
|
await dataCarreraPlantel()
|
2020-10-01 23:58:20 -05:00
|
|
|
await dataEquipo()
|
2020-10-01 16:20:56 -05:00
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
'\nSe ha instalado exitosamente los catalogos.\n'.underline.bold.green
|
|
|
|
|
)
|
|
|
|
|
process.exit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install()
|