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;