diff --git a/src/shows/shows.service.ts b/src/shows/shows.service.ts index f433f4c..7b38930 100644 --- a/src/shows/shows.service.ts +++ b/src/shows/shows.service.ts @@ -1,25 +1,36 @@ import { Injectable } from '@nestjs/common'; import { ShowDto } from './dto/show.dto'; +import { InjectModel } from '@nestjs/mongoose'; +import { Show } from './entities/show.entity'; +import { Model } from 'mongoose'; @Injectable() export class ShowsService { - create(dto: ShowDto) { - return 'This action adds a new show'; + constructor(@InjectModel('Show') private showModel: Model) {} + + async create(dto: ShowDto): Promise { + const show = new this.showModel(dto); + return show.save(); } - findAll() { - return `This action returns all shows`; + async findAll(): Promise { + return this.showModel.find(); } - findOne(id: number) { - return `This action returns a #${id} show`; + async findId(id: string): Promise { + return this.showModel.findById(id); } - update(id: number, dto: ShowDto) { - return `This action updates a #${id} show`; + async find(name: string) { + const regex = new RegExp(name, 'i'); + return this.showModel.find({ title: { $regex: regex } }); } - remove(id: number) { - return `This action removes a #${id} show`; + async update(id: string, dto: ShowDto): Promise { + return this.showModel.findByIdAndUpdate(id, { $set: dto }, { new: true }); + } + + async remove(id: string): Promise { + return this.showModel.findByIdAndDelete(id); } }