basic-expressjs/services/movies.js

34 lines
754 B
JavaScript
Raw Permalink Normal View History

2021-09-15 18:47:11 +00:00
const MongoLib = require('../lib/mongo');
class MoviesService {
constructor() {
this.collection = 'movies';
this.mongoDB = new MongoLib();
}
async list({ tags }) {
const query = tags && { tags: { $in: tags }};
const movies = await this.mongoDB.getAll(this.collection, query);
return movies || [];
}
async get(id) {
const movie = await this.mongoDB.get(this.collection, id);
return movie || {};
}
async create(movie) {
return await this.mongoDB.create(this.collection, movie);
}
async update(id, movie = {}) {
return await this.mongoDB.update(this.collection, id, movie);
}
async delete(id) {
return await this.mongoDB.delete(this.collection, id);
}
}
module.exports = MoviesService;