feat: endpoint for create video service

This commit is contained in:
Rafi Arrafif
2026-01-30 15:18:00 +07:00
parent 0521c27834
commit ab0c8afca4
6 changed files with 83 additions and 1 deletions

View File

@ -191,6 +191,7 @@ Table video_services {
hexColor String [not null]
endpointVideo String [not null]
endpointThumbnail String
endpointDownload String
creator users [not null]
createdBy String [not null]
deletedAt DateTime

View File

@ -229,6 +229,7 @@ model VideoService {
hexColor String @db.VarChar(10)
endpointVideo String @db.Text
endpointThumbnail String? @db.Text
endpointDownload String?
creator User @relation("UserVideoServices", fields: [createdBy], references: [id])
createdBy String @db.Uuid
deletedAt DateTime?

View File

@ -0,0 +1,32 @@
import { Context } from "elysia";
import { mainErrorHandler } from "../../../helpers/error/handler";
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
import { createVideoServiceInternalService } from "../services/http/createVideoService.service";
export interface CreateVideoServiceBodyRequest {
name: string;
domain: string;
logo: string;
hexColor: string;
endpointVideo: string;
endpointThumbnail: string;
endpointDownload?: string;
}
export const createVideoServiceInternalController = async (
ctx: Context & { body: CreateVideoServiceBodyRequest },
) => {
try {
const createdVideoService = await createVideoServiceInternalService(
ctx.body,
);
return returnWriteResponse(
ctx.set,
201,
"Video service created",
createdVideoService,
);
} catch (error) {
throw mainErrorHandler(ctx.set, error);
}
};

View File

@ -1,7 +1,9 @@
import Elysia from "elysia";
import { bulkInsertEpisodeController } from "./controllers/bulkInsertEpisode.controller";
import { bulkInsertMediaController } from "./controllers/bulkInsertMedia.controller";
import { createVideoServiceInternalController } from "./controllers/createVideoService.controller";
export const internalModule = new Elysia({ prefix: "/internal" })
.post("/media/bulk-insert", bulkInsertMediaController)
.post("/episode/bulk-insert", bulkInsertEpisodeController);
.post("/episode/bulk-insert", bulkInsertEpisodeController)
.post("/video-service", createVideoServiceInternalController);

View File

@ -0,0 +1,23 @@
import { Prisma } from "@prisma/client";
import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
export const createVideoServiceInternalRepository = async (
payload: Omit<Prisma.VideoServiceUncheckedCreateInput, "id">,
) => {
try {
return await prisma.videoService.upsert({
where: {
name: payload.name,
},
create: {
id: generateUUIDv7(),
...payload,
},
update: payload,
});
} catch (error) {
throw new AppError(500, "Failed to create video service", error);
}
};

View File

@ -0,0 +1,23 @@
import { SystemAccountId } from "../../../../config/account/system";
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { CreateVideoServiceBodyRequest } from "../../controllers/createVideoService.controller";
import { createVideoServiceInternalRepository } from "../../repositories/createVideoService.repository";
export const createVideoServiceInternalService = async (
body: CreateVideoServiceBodyRequest,
) => {
try {
return await createVideoServiceInternalRepository({
name: body.name,
domain: body.domain,
logo: body.logo,
hexColor: body.hexColor,
endpointVideo: body.endpointVideo,
endpointThumbnail: body.endpointThumbnail,
endpointDownload: body.endpointDownload,
createdBy: SystemAccountId,
});
} catch (error) {
ErrorForwarder(error);
}
};