Skip to content

Commit eabb29b

Browse files
committed
CRUD functions
1 parent 00d17a4 commit eabb29b

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

locations/locations.service.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,45 @@ async function deleteByID(_id) {
3737
}
3838
}
3939

40-
async function updateDocument(_id) {
41-
Location.findByIdAndUpdate(_id, {filmName : 'Hello World'}, (err, data) => {
42-
if(err){
43-
console.log(err);
44-
}
45-
else {
46-
console.log(data);
47-
}
48-
})
40+
async function updateDocument(filter, update) {
41+
try {
42+
return Location.findOneAndUpdate(filter, update);
43+
} catch (err) {
44+
console.error(err);
45+
return null;
46+
}
4947
}
5048

49+
async function createDocument() {
50+
const newLocation = new Location();
51+
newLocation.filmType = req.body.filmType;
52+
newLocation.filmProducerName = req.body.filmProducerName;
53+
newLocation.endDate = req.body.endDate;
54+
newLocation.filmName = req.body.filmName;
55+
newLocation.district= req.body.district;
56+
newLocation.geolocation = req.body.geolocation;
57+
newLocation.sourceLocationId = req.body.sourceLocationId;
58+
newLocation.filmDirectorName = req.body.filmDirectorName;
59+
newLocation.address = req.body.address;
60+
newLocation.startDate = req.body.startDate;
61+
newLocation.year = req.body.year;
62+
63+
try {
64+
newLocation.save();
65+
return console.log("location saved");
66+
} catch (err) {
67+
console.error(err);
68+
return null;
69+
}
70+
71+
}
5172

5273

5374
module.exports = {
5475
findAll,
5576
querybyID,
5677
queryFilmName,
5778
deleteByID,
58-
updateDocument
79+
updateDocument,
80+
createDocument
5981
};

0 commit comments

Comments
 (0)