iut-hapi/lib/services/favorite.js

37 lines
1.0 KiB
JavaScript

'use strict';
const { Service } = require('@hapipal/schmervice');
module.exports = class FavoriteService extends Service {
async list() {
const { Favorite } = this.server.models();
return Favorite.query();
}
async create(payload) {
const { Favorite } = this.server.models();
return Favorite.query().insert(payload);
}
async get(id) {
const { Favorite } = this.server.models();
return Favorite.query().findById(id);
}
async update(id, payload) {
const { Favorite } = this.server.models();
return Favorite.query().patchAndFetchById(id, payload);
}
async delete(payload) {
const { Favorite } = this.server.models();
return Favorite.query().delete().where(payload);
}
async getByMovieAndUser(movieId, userId) {
const { Favorite } = this.server.models();
return Favorite.query().findOne({movie_id: movieId, user_id: userId});
}
}