-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress-Controller.js
73 lines (66 loc) · 2.44 KB
/
address-Controller.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const addressModel = require('../model/address-model')
const categoryController = require('../controllers/category-Controller')
const productController = require('../controllers/product-Controller');
const async = require('hbs/lib/async');
const { promise } = require('bcrypt/promises');
const { Promise } = require('mongoose');
const { response } = require('../app');
module.exports = {
addAddress: (addressdata, userid) => {
console.log(userid, 'useriDDDDDDDDDDDD');
return new Promise(async (res, rej) => {
const address = new addressModel({
Name: addressdata.name,
LastName: addressdata.lastname,
Number: addressdata.number,
Pincode: addressdata.pincode,
Locality: addressdata.locality,
Address: addressdata.address,
State: addressdata.state,
LandMark: addressdata.landmark,
Housename: addressdata.housename,
userId: userid
})
address.save().then((address) => {
res(address)
console.log(address);
})
})
},
getAddress: (userid) => {
return new Promise(async (res, rej) => {
const useraddress = await addressModel.find({ userId: userid }).lean()
res(useraddress)
})
},
getAddressValue: (addressid) => {
return new Promise(async (res, rej) => {
let usersaddress = await addressModel.findOne({ _id: addressid }).lean()
res(usersaddress)
})
},
editAddress: (userdata, addressid) => {
return new Promise(async (res, rej) => {
await addressModel.findByIdAndUpdate(addressid, {
Name: userdata.name,
LastName: userdata.lastname,
Number: userdata.number,
Pincode: userdata.pincode,
Locality: userdata.locality,
Address: userdata.address,
State: userdata.state,
LandMark: userdata.landmark,
Housename: userdata.housename
}).then((response) => {
res(response)
})
})
},
deleteAddress: (addressid) => {
return new Promise(async (res, rej) => {
addressModel.findByIdAndDelete({ _id: addressid }).then((response) => {
res(response)
})
})
}
}