-
Notifications
You must be signed in to change notification settings - Fork 0
/
concern-controller.js
48 lines (37 loc) · 1.44 KB
/
concern-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
const mongoose = require('mongoose');
const AutomovilModel = require('./concern-model.js');
const Automovil = function Constructor(options) {
Object.assign(this, options);
this.Model = AutomovilModel;
return this;
};
Automovil.prototype.findAll = function ControllerFindAll(options) {
let result = this.Model.find({})
.select(options.fieldsToFetch)
.sort({})
.limit(options.recordsPerPage || process.env.RECORDS_PER_PAGE || null)
.exec();
return result;
};
Automovil.prototype.findOne = function ControllerFindOne(options) {
let result = this.Model.findOne({ _id: mongoose.Types.ObjectId(options.automovilId) })
.select(options.fieldsToFetch)
.sort({})
.limit(options.recordsPerPage || process.env.RECORDS_PER_PAGE || null)
.exec();
return result;
};
Automovil.prototype.addNew = function ControllerCreate(options) {
const newAutomovilValues = options.automovilValues;
const newAutomovil = new this.Model(newAutomovilValues);
return newAutomovil.save();
};
Automovil.prototype.patch = function ControllerPatch(options) {
delete options.automovilValues.created_at;
options.automovilValues.updated_at = new Date();
return this.Model.update({ _id: mongoose.Types.ObjectId(options.automovilId) }, options.automovilValues, {});
};
Automovil.prototype.delete = function ControllerDelete(options) {
return this.Model.remove({ _id: mongoose.Types.ObjectId(options.automovilId) });
};
module.exports = Automovil;