👔 feat: implement database repository for get media by slug
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 1m51s
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 1m51s
This commit is contained in:
@ -9,7 +9,7 @@ export const getMediaBySlugController = async (ctx: {
|
|||||||
params: Static<typeof getMediaBySlugSchema.params>;
|
params: Static<typeof getMediaBySlugSchema.params>;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const mediaData = getMediaBySlugService(ctx.params.slug);
|
const mediaData = await getMediaBySlugService(ctx.params.slug);
|
||||||
return returnReadResponse(ctx.set, 200, "Media fetched successfully", mediaData);
|
return returnReadResponse(ctx.set, 200, "Media fetched successfully", mediaData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return mainErrorHandler(ctx.set, error);
|
return mainErrorHandler(ctx.set, error);
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
import { AppError } from "../../../../helpers/error/instances/app";
|
||||||
|
import { prisma } from "../../../../utils/databases/prisma/connection";
|
||||||
|
|
||||||
|
export const selectMediaBySlugRepository = async (slug: string) => {
|
||||||
|
try {
|
||||||
|
return await prisma.media.findUnique({
|
||||||
|
where: { slug },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new AppError(500, "Failed to fetch media by slug", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,8 +1,13 @@
|
|||||||
|
import { AppError } from "../../../../helpers/error/instances/app";
|
||||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
|
import { selectMediaBySlugRepository } from "../../repositories/SELECT/selectMediaBySlug.repository";
|
||||||
|
|
||||||
export const getMediaBySlugService = (slug: string) => {
|
export const getMediaBySlugService = async (slug: string) => {
|
||||||
try {
|
try {
|
||||||
return `Mengambil media dengan slug '${slug}'`;
|
const mediaData = await selectMediaBySlugRepository(slug);
|
||||||
|
if (!mediaData) throw new AppError(404, "Media not found with the provided slug.");
|
||||||
|
|
||||||
|
return mediaData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ErrorForwarder(error);
|
ErrorForwarder(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user