2017-06-17 17:01:50 +02:00
|
|
|
module.exports = {
|
2017-08-29 19:34:34 +02:00
|
|
|
find: async function (params) {
|
2017-09-14 16:33:56 +02:00
|
|
|
return await this
|
2017-06-17 17:01:50 +02:00
|
|
|
.forge()
|
2017-06-18 17:23:58 +02:00
|
|
|
.fetchAll({
|
2017-09-14 16:33:56 +02:00
|
|
|
withRelated: this.associations.map(x => x.alias).join(' ')
|
2017-06-18 17:23:58 +02:00
|
|
|
});
|
2017-06-17 17:01:50 +02:00
|
|
|
},
|
|
|
|
|
2017-08-29 19:34:34 +02:00
|
|
|
count: async function (params) {
|
2017-09-14 16:33:56 +02:00
|
|
|
return await this
|
2017-06-17 17:01:50 +02:00
|
|
|
.forge()
|
|
|
|
.count();
|
|
|
|
},
|
|
|
|
|
2017-09-14 16:33:56 +02:00
|
|
|
findOne: async function (params) {
|
|
|
|
return await this
|
|
|
|
.forge({
|
|
|
|
[this.primaryKey]: params[this.primaryKey]
|
|
|
|
})
|
2017-06-17 17:01:50 +02:00
|
|
|
.fetch();
|
|
|
|
},
|
|
|
|
|
2017-09-14 16:33:56 +02:00
|
|
|
create: async function (params) {
|
|
|
|
return await this
|
2017-06-17 17:01:50 +02:00
|
|
|
.forge()
|
|
|
|
.save(params.values);
|
|
|
|
},
|
|
|
|
|
2017-09-14 16:33:56 +02:00
|
|
|
update: async function (params) {
|
|
|
|
return await this
|
|
|
|
.forge({
|
|
|
|
[this.primaryKey]: params[this.primaryKey]
|
|
|
|
})
|
|
|
|
.save(params.values, {
|
|
|
|
patch: true
|
|
|
|
});
|
2017-06-17 17:01:50 +02:00
|
|
|
},
|
|
|
|
|
2017-09-14 16:33:56 +02:00
|
|
|
delete: async function (params) {
|
|
|
|
return await params.model
|
|
|
|
.forge({
|
|
|
|
[this.primaryKey]: params[this.primaryKey]
|
|
|
|
})
|
2017-06-17 17:01:50 +02:00
|
|
|
.destroy();
|
|
|
|
}
|
2017-08-29 19:34:34 +02:00
|
|
|
};
|