47 lines
908 B
JavaScript
Raw Normal View History

const _ = require('lodash');
module.exports = {
find: async function (params) {
return this
.find()
.limit(Number(params.limit))
.sort(params.sort)
.skip(Number(params.skip));
},
count: async function (params) {
return Number(await this
.count());
},
findOne: async function (params) {
return this
.findOne({
[this.primaryKey]: params.id
})
.populate(this.associations.map(x => x.alias).join(' '));
},
create: async function (params) {
2017-09-14 12:19:24 +02:00
console.log(params);
return await this
.create(params.values);
},
update: async function (params) {
2017-09-11 18:17:09 +02:00
return await this
.update({
[this.primaryKey]: params.id
2017-09-11 18:17:09 +02:00
}, params.values, {
strict: false
2017-09-11 18:17:09 +02:00
});
},
delete: async function (params) {
return await this
.remove({
[this.primaryKey]: params.id
});
}
};