diff --git a/src/controllers/PostsController.ts b/src/controllers/PostsController.ts index 3c0b4e4..251a316 100644 --- a/src/controllers/PostsController.ts +++ b/src/controllers/PostsController.ts @@ -213,10 +213,7 @@ export class PostsController { // Personnal movies posts case PostKind.POST_KIND_MOVIE: - const movieID = h.postInt("movieID"); - - if(!await MoviesHelper.DoesUserHas(h.getUserId(), movieID)) - h.error(401, "You are not authorized to use this movie!"); + const movieID = await h.postMovieID("movieID"); newPost.movieID = movieID; diff --git a/src/entities/BaseRequestsHandler.ts b/src/entities/BaseRequestsHandler.ts index 06339ca..31e5a4b 100644 --- a/src/entities/BaseRequestsHandler.ts +++ b/src/entities/BaseRequestsHandler.ts @@ -18,6 +18,7 @@ import { ConversationsHelper } from "../helpers/ConversationsHelper"; import { AbstractUserConnectionContainer } from "./UserConnectionContainer"; import { CustomEmoji } from "./CustomEmoji"; import { CustomEmojisHelper } from "../helpers/CustomEmojisHelper"; +import { MoviesHelper } from "../helpers/MoviesHelper"; export abstract class BaseRequestsHandler implements AbstractUserConnectionContainer { @@ -437,4 +438,18 @@ export abstract class BaseRequestsHandler implements AbstractUserConnectionConta return info; } + + /** + * Get the ID of a movie included in a POST request + * + * @param name The name of the POSt field containing movie ID + */ + public async postMovieID(name: string) : Promise { + const movieID = this.postInt(name); + + if(!await MoviesHelper.DoesUserHas(this.getUserId(), movieID)) + this.error(401, "You are not authorized to use this movie!"); + + return movieID; + } } \ No newline at end of file