Shows: complete service
This commit is contained in:
parent
f0cf48fc87
commit
00d57b4feb
1 changed files with 21 additions and 10 deletions
|
|
@ -1,25 +1,36 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { ShowDto } from './dto/show.dto';
|
import { ShowDto } from './dto/show.dto';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
import { Show } from './entities/show.entity';
|
||||||
|
import { Model } from 'mongoose';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShowsService {
|
export class ShowsService {
|
||||||
create(dto: ShowDto) {
|
constructor(@InjectModel('Show') private showModel: Model<Show>) {}
|
||||||
return 'This action adds a new show';
|
|
||||||
|
async create(dto: ShowDto): Promise<any> {
|
||||||
|
const show = new this.showModel(dto);
|
||||||
|
return show.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
async findAll(): Promise<Show[]> {
|
||||||
return `This action returns all shows`;
|
return this.showModel.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id: number) {
|
async findId(id: string): Promise<any> {
|
||||||
return `This action returns a #${id} show`;
|
return this.showModel.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, dto: ShowDto) {
|
async find(name: string) {
|
||||||
return `This action updates a #${id} show`;
|
const regex = new RegExp(name, 'i');
|
||||||
|
return this.showModel.find({ title: { $regex: regex } });
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
async update(id: string, dto: ShowDto): Promise<any> {
|
||||||
return `This action removes a #${id} show`;
|
return this.showModel.findByIdAndUpdate(id, { $set: dto }, { new: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(id: string): Promise<any> {
|
||||||
|
return this.showModel.findByIdAndDelete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue