♻️ refactor: add schema to all controllers in internal module
This commit is contained in:
@ -1,79 +1,26 @@
|
||||
import { Context } from "elysia";
|
||||
import { Context, Static } from "elysia";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { createVideoServiceInternalService } from "../services/http/createVideoService.service";
|
||||
|
||||
export interface CreateVideoServiceInternalBodyRequest {
|
||||
name: string;
|
||||
domain: string;
|
||||
logo: string;
|
||||
hexColor: string;
|
||||
endpointVideo: string;
|
||||
endpointThumbnail: string;
|
||||
endpointDownload?: string;
|
||||
}
|
||||
import { createVideoServiceInternalSchema } from "../schemas/createVideoServiceInternal.schema";
|
||||
|
||||
/**
|
||||
* @function createVideoServiceInternalController
|
||||
* @description Perform creation of a new video service. This operation adds a new video service to the database based on the provided data.
|
||||
* Controller for creating a new video service.
|
||||
*
|
||||
* @param {Context & { body: CreateVideoServiceInternalBodyRequest }} ctx
|
||||
* The context object containing the request body.
|
||||
* The body must include:
|
||||
* - name: string - The name of the video service.
|
||||
* - domain: string - The domain of the video service.
|
||||
* - logo: string - The logo URL of the video service.
|
||||
* - hexColor: string - The hex color associated with the video service.
|
||||
* - endpointVideo: string - The endpoint URL for video streaming.
|
||||
* - endpointThumbnail: string - The endpoint URL for thumbnails.
|
||||
* - endpointDownload?: string - (Optional) The endpoint URL for downloads.
|
||||
* This controller handles the HTTP request for creating a new video service.
|
||||
* It validates the incoming request body against the defined schema,
|
||||
* invokes the service layer to perform the creation logic,
|
||||
* and returns an appropriate HTTP response based on the outcome of the operation.
|
||||
*
|
||||
* @example
|
||||
* Request route: POST /internal/video-service
|
||||
* Request body:
|
||||
* {
|
||||
* "name": "Example Video Service",
|
||||
* "domain": "example.com",
|
||||
* "logo": "https://example.com/logo.png",
|
||||
* "hexColor": "#FF5733",
|
||||
* "endpointVideo": "https://api.example.com/videos",
|
||||
* "endpointThumbnail": "https://api.example.com/thumbnails",
|
||||
* "endpointDownload": "https://api.example.com/downloads"
|
||||
* },
|
||||
*
|
||||
* @returns {Promise<Object>}
|
||||
* A response object indicating success or failure.
|
||||
* Return example:
|
||||
* {
|
||||
* success: true,
|
||||
* status: 201,
|
||||
* message: "Video service created",
|
||||
* data: { ...createdVideoService } // 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: <Status Code>,
|
||||
* message: "<Error Message>",
|
||||
* error: { ...errorDetails } // Additional error details if available and the env run on development mode
|
||||
* }
|
||||
* See OpenAPI documentation for request/response schema.
|
||||
*/
|
||||
export const createVideoServiceInternalController = async (
|
||||
ctx: Context & { body: CreateVideoServiceInternalBodyRequest },
|
||||
) => {
|
||||
export const createVideoServiceInternalController = async (ctx: {
|
||||
set: Context["set"];
|
||||
body: Static<typeof createVideoServiceInternalSchema.body>;
|
||||
}) => {
|
||||
try {
|
||||
const createdVideoService = await createVideoServiceInternalService(
|
||||
ctx.body,
|
||||
);
|
||||
return returnWriteResponse(
|
||||
ctx.set,
|
||||
201,
|
||||
"Video service created",
|
||||
createdVideoService,
|
||||
);
|
||||
const createdVideoService = await createVideoServiceInternalService(ctx.body);
|
||||
return returnWriteResponse(ctx.set, 201, "Video service created", createdVideoService);
|
||||
} catch (error) {
|
||||
throw mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user