-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-reset.js
55 lines (50 loc) · 1.64 KB
/
db-reset.js
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
const fs = require('fs');
const faker = require('faker');
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
//database file
const adapter = new FileSync('db.json');
const db = low(adapter);
if(process.argv[2] === 'dynamic') {
initDB();
} else {
// destination.txt will be created or overwritten by default.
fs.copyFile('db-reset.json', 'db.json', (err) => {
if (err) throw err;
console.log('db-reset.json was copied to db.json');
});
}
function initDB() {
db.assign({
company: {
name: faker.company.companyName(),
city: faker.address.city(),
adress: faker.address.streetName() + faker.address.streetAddress(),
country: faker.address.country()
},
customers: [
{
id: faker.random.uuid(),
name: faker.name.findName(),
jobTitle: faker.name.jobTitle(),
email: faker.internet.email(),
phone: faker.phone.phoneNumber()
},
{
id: faker.random.uuid(),
name: faker.name.findName(),
jobTitle: faker.name.jobTitle(),
email: faker.internet.email(),
phone: faker.phone.phoneNumber()
},
{
id: faker.random.uuid(),
name: faker.name.findName(),
jobTitle: faker.name.jobTitle(),
email: faker.internet.email(),
phone: faker.phone.phoneNumber()
}],
count: 0 })
.write();
console.log('db.json was successfully reseted');
}