39
rated 0 times
[
40]
[
1]
/ answers: 1 / hits: 9948
/ 2 Years ago, wed, january 12, 2022, 12:00:00
const movie = await this.movieService.getOne(movie_id);
if(!movie){
throw new Error(
JSON.stringify({
message:'some message',
status:'http status'
})
);
}
const rating = await this.ratingRepository.find({where:{movie});
return rating;
And after it use try catch in controller and throw HttpExeption.
async getAllByMovie(@Param('movie_id') movie_id:string):Promise<Rating[]>{
try{
const ratings = await this.ratingService.getAllRatingsByMovie(Number(movie_id));
return ratings;
}catch(err){
const {message,status} = JSON.parse(err.message);
throw new HttpExeption(message,status);
}
}
Is it good or not?
More From » node.js