-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveData.js
More file actions
38 lines (32 loc) · 894 Bytes
/
Copy pathremoveData.js
File metadata and controls
38 lines (32 loc) · 894 Bytes
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
import inquirer from 'inquirer';
import chalk from 'chalk';
import fs from 'fs';
import queryDB from './queryDB.js';
import dbFileCheck from './dbFileCheck.js';
export default async function removeData(info) {
dbFileCheck();
try {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'recordID',
message: chalk.blue('Ingresa el ID del Registro:'),
},
]);
let remnantData = [];
info.forEach((element) => {
if (element.id !== answers.recordID) {
remnantData.push(element);
}
});
fs.writeFile('bd.json', JSON.stringify(remnantData), function (err) {
if (err) {
console.log(chalk.red(err));
}
console.log(chalk.red('¡Dato eliminado correctamente!'));
});
} catch (error) {
console.log(chalk.white.bgRed('¡Algo salió mal!', error));
}
}
queryDB(removeData);