Skip to content
Snippets Groups Projects
Commit fccbd65e authored by Martin Korec's avatar Martin Korec
Browse files

fix: add addCategory function

parent 0594209e
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,11 @@ export class MoviesController {
return await this.moviesService.findOne(id);
}
@Patch(':id/:categoryName')
async addCategory(@Param('id') id: string, @Param('categoryName') categoryName: string) {
return await this.moviesService.addCategory(id, categoryName);
}
@Patch(':id')
async update(@Param('id') id: string, @Body() updateMovieDto: UpdateMovieDto) {
return await this.moviesService.update(id, updateMovieDto);
......
......@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { CreateMovieDto } from './dto/create-movie.dto';
import { UpdateMovieDto } from './dto/update-movie.dto';
import { PrismaService } from '../../prisma.service';
import { CreateCategoryDto } from '../categories/dto/create-category.dto';
@Injectable()
export class MoviesService {
......@@ -25,6 +26,37 @@ export class MoviesService {
});
}
addCategory(movieId: string, categoryName: string) {
this.prisma.category.update({
data: {
movies: {
connect: {
id: movieId,
},
},
},
where: {
name: categoryName,
},
});
return this.prisma.movie.update({
data: {
categories: {
connect: {
name: categoryName,
},
},
},
where: {
id: movieId,
},
include: {
categories: true,
},
});
}
update(id: string, updateMovieDto: UpdateMovieDto) {
return `This action updates a #${id} movie`;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment