✨ feat: endpoint for create video service
This commit is contained in:
@ -191,6 +191,7 @@ Table video_services {
|
|||||||
hexColor String [not null]
|
hexColor String [not null]
|
||||||
endpointVideo String [not null]
|
endpointVideo String [not null]
|
||||||
endpointThumbnail String
|
endpointThumbnail String
|
||||||
|
endpointDownload String
|
||||||
creator users [not null]
|
creator users [not null]
|
||||||
createdBy String [not null]
|
createdBy String [not null]
|
||||||
deletedAt DateTime
|
deletedAt DateTime
|
||||||
|
|||||||
@ -229,6 +229,7 @@ model VideoService {
|
|||||||
hexColor String @db.VarChar(10)
|
hexColor String @db.VarChar(10)
|
||||||
endpointVideo String @db.Text
|
endpointVideo String @db.Text
|
||||||
endpointThumbnail String? @db.Text
|
endpointThumbnail String? @db.Text
|
||||||
|
endpointDownload String?
|
||||||
creator User @relation("UserVideoServices", fields: [createdBy], references: [id])
|
creator User @relation("UserVideoServices", fields: [createdBy], references: [id])
|
||||||
createdBy String @db.Uuid
|
createdBy String @db.Uuid
|
||||||
deletedAt DateTime?
|
deletedAt DateTime?
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,7 +1,9 @@
|
|||||||
import Elysia from "elysia";
|
import Elysia from "elysia";
|
||||||
import { bulkInsertEpisodeController } from "./controllers/bulkInsertEpisode.controller";
|
import { bulkInsertEpisodeController } from "./controllers/bulkInsertEpisode.controller";
|
||||||
import { bulkInsertMediaController } from "./controllers/bulkInsertMedia.controller";
|
import { bulkInsertMediaController } from "./controllers/bulkInsertMedia.controller";
|
||||||
|
import { createVideoServiceInternalController } from "./controllers/createVideoService.controller";
|
||||||
|
|
||||||
export const internalModule = new Elysia({ prefix: "/internal" })
|
export const internalModule = new Elysia({ prefix: "/internal" })
|
||||||
.post("/media/bulk-insert", bulkInsertMediaController)
|
.post("/media/bulk-insert", bulkInsertMediaController)
|
||||||
.post("/episode/bulk-insert", bulkInsertEpisodeController);
|
.post("/episode/bulk-insert", bulkInsertEpisodeController)
|
||||||
|
.post("/video-service", createVideoServiceInternalController);
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user