Shows: complete service

This commit is contained in:
Toast 2025-01-23 10:34:29 +01:00
parent f0cf48fc87
commit 00d57b4feb

View file

@ -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<Show>) {}
async create(dto: ShowDto): Promise<any> {
const show = new this.showModel(dto);
return show.save();
}
findAll() {
return `This action returns all shows`;
async findAll(): Promise<Show[]> {
return this.showModel.find();
}
findOne(id: number) {
return `This action returns a #${id} show`;
async findId(id: string): Promise<any> {
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<any> {
return this.showModel.findByIdAndUpdate(id, { $set: dto }, { new: true });
}
async remove(id: string): Promise<any> {
return this.showModel.findByIdAndDelete(id);
}
}