-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (48 loc) · 1.23 KB
/
index.js
File metadata and controls
64 lines (48 loc) · 1.23 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
const mongoose=require('mongoose');
const key1=require('./keys');
mongoose.Promise=global.Promise;
const db = mongoose.connect(key1.key,{useNewUrlParser : true});
const Customer= require('./model/customer');
// Add a customer
const addCustomer=(customer) => {
Customer.create(customer).then(customer =>{
console.info("New Customer Added");
//db.close();
});
}
// To find customer
const findCustomer = (name) => {
var search = new RegExp(name,'i');
Customer.find({ $or : [{firstname : search},{ lastname : search}]}).then(customer => {
console.info(customer);
console.log(`${customer.length} matched`);
//db0.close();
});
}
// Update a customer
const updateCustomer = (id,customer) => {
Customer.update({id},customer).then(customer => {
console.log("Customer Updated");
//db.close();
});
}
// Remove a customer
const removeCustomer = (id) => {
Customer.remove({id}).then((customer) => {
console.log("Customer removed");
});
}
// List all Customers
const listCustomers = () => {
Customer.find().then(customer => {
console.log(customer);
console.info(`${customer.length} founded`);
});
}
module.exports = {
addCustomer,
findCustomer,
updateCustomer,
removeCustomer,
listCustomers
}