From 10a19a066ded4a29ce7888c713e7e7afb7e97ad8 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Fri, 30 Jan 2026 04:23:47 +0700 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=93=9D=20docs:=20add=20documentation?= =?UTF-8?q?=20for=20bulk=20insert=20media?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/bulkInsertAnime.controller.ts | 21 ------- .../controllers/bulkInsertMedia.controller.ts | 56 +++++++++++++++++++ src/modules/internal/index.ts | 4 +- 3 files changed, 58 insertions(+), 23 deletions(-) delete mode 100644 src/modules/internal/controllers/bulkInsertAnime.controller.ts create mode 100644 src/modules/internal/controllers/bulkInsertMedia.controller.ts diff --git a/src/modules/internal/controllers/bulkInsertAnime.controller.ts b/src/modules/internal/controllers/bulkInsertAnime.controller.ts deleted file mode 100644 index 6b06b0a..0000000 --- a/src/modules/internal/controllers/bulkInsertAnime.controller.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Context } from "elysia"; -import { mainErrorHandler } from "../../../helpers/error/handler"; -import { bulkInsertAnimeService } from "../services/http/bulkInsertAnime.service"; -import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; -import { bulkInsertCharWithVAService } from "../services/internal/bulkInsertCharWithVA.service"; - -export const bulkInsertAnimeController = async ( - ctx: Context & { body: { mal_id: number } }, -) => { - try { - const bulkInsertResult = await bulkInsertAnimeService(ctx.body.mal_id); - return returnWriteResponse( - ctx.set, - 201, - "Bulk insert anime operation completed successfully", - bulkInsertResult, - ); - } catch (error) { - return mainErrorHandler(ctx.set, error); - } -}; diff --git a/src/modules/internal/controllers/bulkInsertMedia.controller.ts b/src/modules/internal/controllers/bulkInsertMedia.controller.ts new file mode 100644 index 0000000..a505f20 --- /dev/null +++ b/src/modules/internal/controllers/bulkInsertMedia.controller.ts @@ -0,0 +1,56 @@ +import { Context } from "elysia"; +import { mainErrorHandler } from "../../../helpers/error/handler"; +import { bulkInsertAnimeService } from "../services/http/bulkInsertAnime.service"; +import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; + +/** + * @function bulkInsertAnimeController + * @description Insert new anime to the database only with mal_id. This operation including inserting related data such as genres, studios, producers, licensors, themes, demographics, and relations. + * + * @param {Context & { body: { mal_id: number } }} ctx + * The context object containing the request body. + * The body must include: + * - mal_id: number - The MyAnimeList ID of the anime to be inserted. + * + * @example + * Request route: POST /internal/anime/bulk-insert + * Request body: + * { + * "mal_id": 12345 + * } + * + * @returns {Promise} + * A response object indicating success or failure. + * Return example: + * { + * success: true, + * status: 201, + * message: "Bulk insert anime operation completed successfully", + * data: { ...bulkInsertResult } // Data returned only if the env run on development mode + * } + * + * @throws {Object} + * An error response object if validation fails or an error occurs during bulk insert operation. + * Return example: + * { + * success: false, + * status: , + * message: "", + * error: { ...errorDetails } // Additional error details if available and the env run on development mode + * } + */ +export const bulkInsertMediaController = async ( + ctx: Context & { body: { mal_id: number } }, +) => { + try { + const bulkInsertResult = await bulkInsertAnimeService(ctx.body.mal_id); + return returnWriteResponse( + ctx.set, + 201, + "Bulk insert anime operation completed successfully", + bulkInsertResult, + ); + } catch (error) { + return mainErrorHandler(ctx.set, error); + } +}; diff --git a/src/modules/internal/index.ts b/src/modules/internal/index.ts index e7838c8..b7321b5 100644 --- a/src/modules/internal/index.ts +++ b/src/modules/internal/index.ts @@ -1,7 +1,7 @@ import Elysia from "elysia"; -import { bulkInsertAnimeController } from "./controllers/bulkInsertAnime.controller"; import { bulkInsertEpisodeController } from "./controllers/bulkInsertEpisode.controller"; +import { bulkInsertMediaController } from "./controllers/bulkInsertMedia.controller"; export const internalModule = new Elysia({ prefix: "/internal" }) - .post("/media/bulk-insert", bulkInsertAnimeController) + .post("/media/bulk-insert", bulkInsertMediaController) .post("/episode/bulk-insert", bulkInsertEpisodeController); From 4e8eda081cd9005b914cc70df1ec639faefaf529 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Fri, 30 Jan 2026 05:02:03 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20docs:=20add=20documentation?= =?UTF-8?q?=20for=20bulk=20insert=20episode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bulkInsertEpisode.controller.ts | 41 ++++++++++++++++++- .../controllers/bulkInsertMedia.controller.ts | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/modules/internal/controllers/bulkInsertEpisode.controller.ts b/src/modules/internal/controllers/bulkInsertEpisode.controller.ts index c6bc1ab..125acec 100644 --- a/src/modules/internal/controllers/bulkInsertEpisode.controller.ts +++ b/src/modules/internal/controllers/bulkInsertEpisode.controller.ts @@ -3,7 +3,44 @@ import { mainErrorHandler } from "../../../helpers/error/handler"; import { bulkInsertEpisodeService } from "../services/http/bulkInsertEpisode.service"; import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; -// add pagination query +/** + * @function bulkInsertMediaController + * @description Perform bulk insert of episodes for a specific media. This operation fetches episode data from external sources and inserts them into the database. The page parameter is optional; if not provided, the first page of episodes will be fetched. + * + * @param {Context & { body: { media_mal_id: number }; query: { page?: number } }} ctx + * The context object containing the request body. + * The body must include: + * - media_mal_id: number - The MyAnimeList ID of the media for which episodes will be inserted. + * The query may include: + * - page?: number - (Optional) The page number of episodes to fetch and insert. If not provided, defaults to the first page. + * + * @example + * Request route: POST /internal/episode/bulk-insert + * Request body: + * { + * "media_mal_id": 12345 + * } + * + * @returns {Promise} + * A response object indicating success or failure. + * Return example: + * { + * success: true, + * status: 201, + * message: "Bulk insert episode operation completed successfully", + * data: { ...bulkInsertResult } // Data returned only if the env run on development mode + * } + * + * @throws {Object} + * An error response object if validation fails or an error occurs during bulk insert operation. + * Return example: + * { + * success: false, + * status: , + * message: "", + * error: { ...errorDetails } // Additional error details if available and the env run on development mode + * } + */ export const bulkInsertEpisodeController = async ( ctx: Context & { body: { media_mal_id: number }; query: { page?: number } }, ) => { @@ -15,7 +52,7 @@ export const bulkInsertEpisodeController = async ( return returnWriteResponse( ctx.set, 201, - "Success bulk insert for episode", + "Bulk insert episode operation completed successfully", bulkInsertResult, ); } catch (err) { diff --git a/src/modules/internal/controllers/bulkInsertMedia.controller.ts b/src/modules/internal/controllers/bulkInsertMedia.controller.ts index a505f20..f27998b 100644 --- a/src/modules/internal/controllers/bulkInsertMedia.controller.ts +++ b/src/modules/internal/controllers/bulkInsertMedia.controller.ts @@ -4,7 +4,7 @@ import { bulkInsertAnimeService } from "../services/http/bulkInsertAnime.service import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; /** - * @function bulkInsertAnimeController + * @function bulkInsertMediaController * @description Insert new anime to the database only with mal_id. This operation including inserting related data such as genres, studios, producers, licensors, themes, demographics, and relations. * * @param {Context & { body: { mal_id: number } }} ctx From ce56e13f3041fa071096b473cb9121b107a1d696 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Fri, 30 Jan 2026 05:02:41 +0700 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20docs:=20complete=20paginatio?= =?UTF-8?q?n=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/controllers/bulkInsertEpisode.controller.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/internal/controllers/bulkInsertEpisode.controller.ts b/src/modules/internal/controllers/bulkInsertEpisode.controller.ts index 125acec..6d450dd 100644 --- a/src/modules/internal/controllers/bulkInsertEpisode.controller.ts +++ b/src/modules/internal/controllers/bulkInsertEpisode.controller.ts @@ -20,6 +20,8 @@ import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; * { * "media_mal_id": 12345 * } + * Query parameter: + * ?page=2 (Optional, specifies the page number of episodes to fetch and insert) * * @returns {Promise} * A response object indicating success or failure.