Repository navigation
Expand file tree
/
Copy pathaddData.js
More file actions
136 lines (130 loc) · 3.75 KB
/
Copy pathaddData.js
File metadata and controls
136 lines (130 loc) · 3.75 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import inquirer from 'inquirer';
import chalk from 'chalk';
import fs from 'fs';
import { v4 as uuidv4 } from 'uuid';
import queryDB from './queryDB.js';
export default async function addData(info) {
try {
const answers = await inquirer.prompt([
{
type: 'number',
name: 'wi',
message: chalk.green('Ingresa el WI:'),
},
{
type: 'input',
name: 'iprPet',
message: chalk.green('Ingresa la PET/IPR:'),
},
{
type: 'input',
name: 'description',
message: chalk.green('Ingresa la descripción:'),
},
{
type: 'list',
name: 'tdp',
message: chalk.green('Ingresa Coord. TDP:'),
choices: [
{ name: 'Omar Loayza Becerra', value: 'Omar Loayza Becerra' },
{ name: 'Julio Carmen Rodriguez', value: 'Julio Carmen Rodriguez' },
{ name: 'Marco Espinoza Valencia', value: 'Marco Espinoza Valencia' },
{ name: 'Fiorella Florencio Inga', value: 'Fiorella Florencio Inga' },
{ name: 'Saul Salhuana Machuca', value: 'Saul Salhuana Machuca' },
],
},
{
type: 'input',
name: 'fechaPaP',
message: chalk.green('Ingresa fecha de pase:'),
},
{
type: 'input',
name: 'horaPaPi',
message: chalk.green('Ingresa hora inicio:'),
},
{
type: 'input',
name: 'horaPaPf',
message: chalk.green('Ingresa hora fin:'),
},
{
type: 'list',
name: 'despliegue',
message: chalk.green('Desplegado por:'),
choices: [
{ name: 'NTTDATA', value: 'NTTDATA' },
{ name: 'TDP', value: 'TDP' },
],
},
{
type: 'input',
name: 'sistema',
message: chalk.green('Ingrese el Sistema:'),
},
{
type: 'list',
name: 'niubiz',
message: chalk.green('Ingresa Coord. Niubiz:'),
choices: [
{ name: 'Cesar Curitomay', value: 'Cesar Curitomay' },
{ name: 'Brando Avila', value: 'Brando Avila' },
{ name: 'Lucia Escudero', value: 'Lucia Escudero' },
{ name: 'Javier Bautista', value: 'Javier Bautista' },
{ name: 'JJaime Alvarado', value: 'Jaime Alvarado' },
],
},
{
type: 'checkbox',
name: 'menu',
message: chalk.green('¿Se modificó el Menu GECOI ?'),
choices: [{ name: 'SI' }, { name: 'NO', checked: true }],
},
{
type: 'checkbox',
name: 'clearing',
message: chalk.green('¿Clearing Controlado?'),
choices: [{ name: 'SI' }, { name: 'NO', checked: true }],
},
]);
const data = {
id: uuidv4(),
wi: answers.wi,
iprPet: answers.iprPet,
description: answers.description,
tdp: answers.tdp,
fechaPaP: answers.fechaPaP,
horaPaPi: answers.horaPaPi,
horaPaPf: answers.horaPaPf,
despliegue: answers.despliegue,
sistema: answers.sistema,
niubiz: answers.niubiz,
menu: answers.menu,
clearing: answers.clearing,
};
info.push(data);
if (fs.existsSync('bd.json')) {
createDetails(info);
} else {
fs.appendFile('bd.json', '[]', (err) => {
if (err) {
console.log(chalk.white.bgRed('No se pudo crear bd.json', err));
return;
}
createDetails(info);
});
}
} catch (error) {
console.log(chalk.white.bgRed('¡Algo salió mal!', error));
}
}
async function createDetails(info) {
await fs.writeFile('bd.json', JSON.stringify(info), function (err) {
if (err) {
console.log(chalk.white.bgRedBright(err));
}
console.log('');
console.log(chalk.black.bgBlue('¡Datos Guardados correctamente!'));
});
}
queryDB(addData);