-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo.js
43 lines (42 loc) · 1.06 KB
/
mongo.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
'use strict';
/**
* function that contains all operations to use in mongoose
*
* */
class Model {
constructor(schema) {
this.schema = schema;
}
/**
* creates the record object as a new mongoose entry
* @param {object} record is a valid object input ready to use in schema.
*/
create(record) {
let newRecord = new this.schema(record);
return newRecord.save();
}
/**
* gets the specified ID from mongoose db
* @param {String} _id is a mongoose generated ID to search for
*/
get(_id) {
let obj = _id ? {_id} : {};
return this.schema.find(obj);
}
/**
* updates the specified _id with the record object
* @param {String} _id is a mongoose generated ID to search for
* @param {object} record is a valid object input ready to use in schema.
*/
update(_id, record) {
return this.schema.findByIdAndUpdate(_id, record);
}
/**
* deletes the specified ID from mongoose db
* @param {String} _id is a mongoose generated ID to search for
*/
delete(_id) {
return this.schema.findByIdAndDelete(_id);
}
}
module.exports = Model;