Cinevoraces / cinevoraces

3 stars 1 forks source link

API - Hook throwIfMovieFound bug #141

Closed Julien-Goletto closed 1 year ago

Julien-Goletto commented 1 year ago

preHandlerMovies.ts

  /**
   * @preValidation 
   * @description Movie existence verification
   */// eslint-disable-next-line @typescript-eslint/no-unused-vars
  fastify.decorate('throwIfMovieFound', async (request: Request<{ Params?: { id: number }; }>, reply: Reply) => {
    const { _errorService, _movieService } = fastify;
    const isMovie = await _movieService.checkMovieExistanceById(request.params.id);
    if (isMovie)
      _errorService.send(EErrorMessages.ALREADY_POSTED_MOVIE, 404);
  });

preHandler must use checkMovieExistanceByName to work.