✨ feat: add service to fetch all videos from videoService
This commit is contained in:
@ -48,7 +48,8 @@ export const updateAllEpisodeThumbnailController = async (
|
|||||||
return returnWriteResponse(
|
return returnWriteResponse(
|
||||||
ctx.set,
|
ctx.set,
|
||||||
204,
|
204,
|
||||||
`Updating ${newEpisodeThumbnailsCount} episode thumbnails successfully.`,
|
`Updating episode thumbnails successfully.`,
|
||||||
|
newEpisodeThumbnailsCount,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return mainErrorHandler(ctx.set, error);
|
return mainErrorHandler(ctx.set, error);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { AppError } from "../../../../helpers/error/instances/app";
|
import { AppError } from "../../../../helpers/error/instances/app";
|
||||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
|
import { getAllVideoServiceWithEpisodeRepository } from "../../../videoService/repositories/GET/getAllVideoServiceWithEpisode.repository";
|
||||||
|
|
||||||
export const updateAllEpisodeThumbnailService = async (
|
export const updateAllEpisodeThumbnailService = async (
|
||||||
serviceReferenceId?: string,
|
serviceReferenceId?: string,
|
||||||
@ -8,7 +9,17 @@ export const updateAllEpisodeThumbnailService = async (
|
|||||||
if (!serviceReferenceId)
|
if (!serviceReferenceId)
|
||||||
throw new AppError(400, "Service Reference ID is required.");
|
throw new AppError(400, "Service Reference ID is required.");
|
||||||
|
|
||||||
return serviceReferenceId;
|
const videosData = await getAllVideoServiceWithEpisodeRepository(
|
||||||
|
serviceReferenceId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!videosData || videosData.length === 0)
|
||||||
|
throw new AppError(
|
||||||
|
404,
|
||||||
|
"No episode with no thumbnail found in the specified video service.",
|
||||||
|
);
|
||||||
|
|
||||||
|
return videosData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ErrorForwarder(error);
|
ErrorForwarder(error);
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/modules/videoService/model.ts
Normal file
3
src/modules/videoService/model.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { prisma } from "../../utils/databases/prisma/connection";
|
||||||
|
|
||||||
|
export const videoServiceModel = prisma.videoService;
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
import { AppError } from "../../../../helpers/error/instances/app";
|
||||||
|
import { videoServiceModel } from "../../model";
|
||||||
|
|
||||||
|
export const getAllVideoServiceWithEpisodeRepository = async (
|
||||||
|
videoServiceId: string,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
return await videoServiceModel.findMany({
|
||||||
|
where: {
|
||||||
|
id: videoServiceId,
|
||||||
|
videos: {
|
||||||
|
some: {
|
||||||
|
episode: {
|
||||||
|
pictureThumbnail: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
endpointThumbnail: true,
|
||||||
|
videos: {
|
||||||
|
select: {
|
||||||
|
thumbnailCode: true,
|
||||||
|
episode: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new AppError(
|
||||||
|
500,
|
||||||
|
"An error occurred while fetching video services with episodes.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user