From b27479cd3e19c6e5afffb1d140d9a72e18cb6b2e Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Wed, 1 Apr 2026 23:38:32 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20resolve=20schema=20type?= =?UTF-8?q?=20error=20in=20getAllMedia=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/getAllMedia.controller.ts | 17 +++--- src/modules/media/index.ts | 5 +- .../media/schemas/getAllMedia.schema.ts | 58 +++++++++++++++++++ 3 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/modules/media/schemas/getAllMedia.schema.ts diff --git a/src/modules/media/controllers/getAllMedia.controller.ts b/src/modules/media/controllers/getAllMedia.controller.ts index fdadf8c..25fc820 100644 --- a/src/modules/media/controllers/getAllMedia.controller.ts +++ b/src/modules/media/controllers/getAllMedia.controller.ts @@ -1,19 +1,16 @@ -import { Context } from "elysia"; +import { Context, Static } from "elysia"; import { mainErrorHandler } from "../../../helpers/error/handler"; import { getAllMediaService } from "../services/http/getAllMedia.service"; import { returnReadResponse } from "../../../helpers/callback/httpResponse"; +import { getAllMediaSchema } from "../schemas/getAllMedia.schema"; -export const getAllMediaController = async ( - ctx: Context & { query: { page: string } }, -) => { +export const getAllMediaController = async (ctx: { + set: Context["set"]; + query: Static; +}) => { try { const mediaData = await getAllMediaService(ctx.query.page); - return returnReadResponse( - ctx.set, - 200, - "Media fetched successfully", - mediaData, - ); + return returnReadResponse(ctx.set, 200, "Media fetched successfully", mediaData); } catch (error) { return mainErrorHandler(ctx.set, error); } diff --git a/src/modules/media/index.ts b/src/modules/media/index.ts index d1cc726..7d94df5 100644 --- a/src/modules/media/index.ts +++ b/src/modules/media/index.ts @@ -2,7 +2,8 @@ import Elysia from "elysia"; import { getAllMediaController } from "./controllers/getAllMedia.controller"; import { getMediaBySlugController } from "./controllers/getMediaBySlug.controller"; import { getMediaBySlugSchema } from "./schemas/getMediaBySlug.schema"; +import { getAllMediaSchema } from "./schemas/getAllMedia.schema"; -export const mediaModule = new Elysia({ prefix: "/media" }) - .get("/", getAllMediaController) +export const mediaModule = new Elysia({ prefix: "/media", tags: ["Media"] }) + .get("/", getAllMediaController, getAllMediaSchema) .get("/:slug", getMediaBySlugController, getMediaBySlugSchema); diff --git a/src/modules/media/schemas/getAllMedia.schema.ts b/src/modules/media/schemas/getAllMedia.schema.ts new file mode 100644 index 0000000..9b382e9 --- /dev/null +++ b/src/modules/media/schemas/getAllMedia.schema.ts @@ -0,0 +1,58 @@ +import { t } from "elysia"; +import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema"; + +export const getAllMediaSchema = { + query: t.Object({ + page: t.String({ description: "The page number for pagination", default: "1" }), + }), + detail: { + summary: "Fetch all media items with pagination", + description: + "Fetch a paginated list of all media items. The 'page' query parameter can be used to specify the page number for pagination.", + responses: { + 200: { + description: "Media items fetched successfully", + content: { + "application/json": { + schema: { + type: "object", + properties: { + success: { type: "boolean", example: true }, + status: { type: "number", example: 200 }, + message: { type: "string", example: "Media fetched successfully" }, + data: { + type: "array", + items: { + type: "object", + properties: { + status: { type: "string", example: "Finished Airing" }, + id: { type: "string", example: "12345" }, + title: { type: "string", example: "Example Media Title" }, + slug: { type: "string", example: "example-media-title" }, + malId: { type: "number", example: 67890 }, + pictureMedium: { type: "string", example: "https://example.com/medium.jpg" }, + pictureLarge: { type: "string", example: "https://example.com/large.jpg" }, + country: { type: "string", example: "JP" }, + score: { type: "number", example: 8.5 }, + startAiring: { type: "string", format: "date-time", example: "2023-01-01T00:00:00Z" }, + endAiring: { type: "string", format: "date-time", example: "2023-12-31T23:59:59Z" }, + synopsis: { type: "string", example: "This is an example synopsis of the media item." }, + ageRating: { type: "string", example: "PG-13" }, + mediaType: { type: "string", example: "Anime" }, + source: { type: "string", example: "Manga" }, + onDraft: { type: "boolean", example: false }, + uploadedBy: { type: "string", example: "admin" }, + deletedAt: { type: "string", format: "date-time", nullable: true, example: null }, + createdAt: { type: "string", format: "date-time", example: "2023-01-01T00:00:00Z" }, + updatedAt: { type: "string", format: "date-time", example: "2023-01-02T00:00:00Z" }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, +} satisfies AppRouteSchema;