👔 feat: add bulk thumbnail update logic
Some checks failed
Integration Tests / integration-tests (pull_request) Failing after 42s
Some checks failed
Integration Tests / integration-tests (pull_request) Failing after 42s
This commit is contained in:
@ -48,8 +48,7 @@ export const updateAllEpisodeThumbnailController = async (
|
||||
return returnWriteResponse(
|
||||
ctx.set,
|
||||
204,
|
||||
`Updating episode thumbnails successfully.`,
|
||||
newEpisodeThumbnailsCount,
|
||||
`Updating ${newEpisodeThumbnailsCount} episode thumbnails successfully.`,
|
||||
);
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { AppError } from "../../../../helpers/error/instances/app";
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { bulkUpdateThumbnailRepository } from "../../../episode/repositories/PUT/bulkUpdateThumbnail.repository";
|
||||
import { getAllVideoServiceWithEpisodeRepository } from "../../../videoService/repositories/GET/getAllVideoServiceWithEpisode.repository";
|
||||
|
||||
export const updateAllEpisodeThumbnailService = async (
|
||||
@ -19,20 +20,20 @@ export const updateAllEpisodeThumbnailService = async (
|
||||
"No episode with no thumbnail found in the specified video service.",
|
||||
);
|
||||
|
||||
const updatePayload = videosData.map((videoService) => {
|
||||
const updatePayload = videosData.flatMap((videoService) => {
|
||||
const { endpointThumbnail, videos } = videoService;
|
||||
return videos
|
||||
.filter((video) => video.thumbnailCode !== null)
|
||||
.map((video) => ({
|
||||
episodeId: video.episode.id,
|
||||
thumbnailCode: endpointThumbnail?.replace(
|
||||
":code:",
|
||||
video.thumbnailCode!,
|
||||
),
|
||||
}));
|
||||
return videos.map((video) => ({
|
||||
episodeId: video.episode.id,
|
||||
thumbnailCode: endpointThumbnail!.replace(
|
||||
":code:",
|
||||
video.thumbnailCode || video.videoCode,
|
||||
),
|
||||
}));
|
||||
});
|
||||
|
||||
return updatePayload;
|
||||
await bulkUpdateThumbnailRepository(updatePayload);
|
||||
|
||||
return updatePayload.length;
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user