From d119a6e6f889777b0d36b6d0627e3cb268add2c7 Mon Sep 17 00:00:00 2001 From: huytran17 Date: Thu, 29 Aug 2024 20:18:14 +0700 Subject: [PATCH] get comments paginated route --- .../comment/validators/get-comments-paginated.ts | 7 +++++++ .../controllers/admin/comment/validators/index.ts | 4 +++- core/server/src/routes/admin/comment.ts | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 core/server/src/data-access/controllers/admin/comment/validators/get-comments-paginated.ts diff --git a/core/server/src/data-access/controllers/admin/comment/validators/get-comments-paginated.ts b/core/server/src/data-access/controllers/admin/comment/validators/get-comments-paginated.ts new file mode 100644 index 00000000..c64fe539 --- /dev/null +++ b/core/server/src/data-access/controllers/admin/comment/validators/get-comments-paginated.ts @@ -0,0 +1,7 @@ +const getCommentsPaginatedRules = { + query: "string", + page: "integer", + entries_per_page: "integer", +}; + +export default getCommentsPaginatedRules; diff --git a/core/server/src/data-access/controllers/admin/comment/validators/index.ts b/core/server/src/data-access/controllers/admin/comment/validators/index.ts index e2e3ea6e..2ae78445 100644 --- a/core/server/src/data-access/controllers/admin/comment/validators/index.ts +++ b/core/server/src/data-access/controllers/admin/comment/validators/index.ts @@ -1,7 +1,9 @@ +import getCommentsPaginatedRules from "./get-comments-paginated"; import hardDeleteCommentRules from "./hard-delete-comment"; export default Object.freeze({ hardDeleteCommentRules, + getCommentsPaginatedRules, }); -export { hardDeleteCommentRules }; +export { getCommentsPaginatedRules, hardDeleteCommentRules }; diff --git a/core/server/src/routes/admin/comment.ts b/core/server/src/routes/admin/comment.ts index 82e75a0d..bf354e00 100644 --- a/core/server/src/routes/admin/comment.ts +++ b/core/server/src/routes/admin/comment.ts @@ -5,12 +5,23 @@ import makeValidator from "../../config/middlewares/validator"; import { AuthorizationRole } from "../../constants/authorization-role"; import { getCommentsController, + getCommentsPaginatedController, hardDeleteCommentController, } from "../../data-access/controllers/admin/comment"; -import { hardDeleteCommentRules } from "../../data-access/controllers/admin/comment/validators"; +import { + getCommentsPaginatedRules, + hardDeleteCommentRules, +} from "../../data-access/controllers/admin/comment/validators"; const commentRouter = Router(); +commentRouter.delete( + "/all-paginated", + makeAuthorization(AuthorizationRole.OWNER_AND_COLLABORATOR), + makeValidator(getCommentsPaginatedRules), + makeExpressCallback(getCommentsPaginatedController) +); + commentRouter.delete( "/hard-delete/:_id", makeAuthorization(AuthorizationRole.OWNER_AND_COLLABORATOR),