✨ feat: endpoint for create video service
This commit is contained in:
@ -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 { 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);
|
||||
|
||||
@ -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