-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-helper.js
42 lines (35 loc) · 876 Bytes
/
db-helper.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
const mongoose = require("mongoose");
const Customer = mongoose.model("Customer", {
displayName: {
type: String,
unique: true,
},
id: String,
saInvoiceId: String,
tipInvoiceId: String,
saPaymentId: String,
tipPaymentId: String,
});
const findCustomerById = async (id) => {
const customer = await Customer.findById(id);
return customer;
};
const findCustomerByDisplayName = async (displayName) => {
const customer = await Customer.findOne({ displayName });
return customer;
};
const findAllCustomers = async () => {
const customers = await Customer.find();
return customers;
};
const updateCustomerById = async (id, data) => {
return Customer.findByIdAndUpdate(id, data).exec();
};
const dbHelper = {
Customer,
findCustomerById,
findCustomerByDisplayName,
findAllCustomers,
updateCustomerById,
};
module.exports = dbHelper;