-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory-Controller.js
78 lines (58 loc) · 2.13 KB
/
category-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
74
75
76
77
const { response } = require("../app");
const categoryModel = require("../model/category-model")
module.exports={
addcategoryData: (categorydata)=>{
return new Promise(async (resolve,reject)=>{
const category = await categoryModel.findOne({categoryname: categorydata.categoryname}).lean();
const response = {
exist:false
}
if(!category){
categoryModel.create(categorydata).then((data)=>{
response.exist = false
response.category = categorydata
resolve(response)
}).catch((err)=>{
console.log('error creating',err)
resolve(err)
})
}else{
response.exist = true
response.category = categorydata
resolve(response)
}
})
},
getcategory: ()=>{
return new Promise(async(resolve,reject)=>{
const categoryname = await categoryModel.find({}).lean()
resolve(categoryname)
})
},
getcategorybyID: (categoryid)=>{
return new Promise(async(resolve,reject)=>{
const categoryname = await categoryModel.findById(categoryid).lean()
console.log(categoryname,"category-name");
resolve(categoryname)
})
},
deletecategory: (categoryid)=>{
return new Promise(async(resolve,reject)=>{
const category = await categoryModel.findByIdAndDelete({_id:categoryid}).lean();
resolve(resolve)
})
},
getcategorydata: (categoryid)=>{
return new Promise(async(resolve,reject)=>{
const category = await categoryModel.find({_id:categoryid}).lean();
resolve(category)
})
},
updatecategory: (categoryid,categoryDetails)=>{
return new Promise((resolve,reject)=>{
categoryModel.findByIdAndUpdate(categoryid,{categoryname:categoryDetails.categoryname}).then((response)=>{
resolve(response)
})
})
}
}