-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (48 loc) · 1.22 KB
/
index.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
56
57
const { info } = require('console');
const http = require('http');
const Customer = require('./models/customer');
const addcustomer = (customer1) => {
const customer = new Customer(customer1);
customer.save().then((x) => {
console.info('New customer added');
});
};
const findcustomer = (id) => {
Customer.find(id, (customer) => {
if (!customer) {
console.info('Not found!');
} else console.info(customer);
});
};
const updatecustomer = ( customer) => {
Customer.update(
{ id:customer.id, name: customer.name, email: customer.email },
(customer) => {
if (!customer) {
console.info('Not found!');
return;
}
console.info(customer);
}
);
};
const deletecustomer = (obj) => {
Customer.remove(obj.id, (message) => {
console.info(message);
});
};
const allcustomers = () => {
Customer.fetchall((data) => {
if (!data) {
console.info('No data found');
return;
}
console.info(data);
console.info(`${data.length} customer(s) found`);
});
};
exports.addcustomer = addcustomer;
exports.findcustomer = findcustomer;
exports.updatecustomer = updatecustomer;
exports.deletecustomer = deletecustomer;
exports.allcustomers = allcustomers;