✨ feat: launch endpoint to insert anime only with malId
This commit is contained in:
@ -6,6 +6,7 @@ import { InsertMediaRepository } from "../repositories/bulkinsertMedia.repositor
|
||||
import { bulkInsertStudiosRepository } from "../repositories/bulkInsertStudios.repository";
|
||||
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
|
||||
import { generateSlug } from "../../../helpers/characters/generateSlug";
|
||||
import { bulkInsertCharWithVAService } from "./internal/bulkInsertCharWithVA.service";
|
||||
|
||||
export const bulkInsertAnimeService = async (malId: number) => {
|
||||
try {
|
||||
@ -16,8 +17,9 @@ export const bulkInsertAnimeService = async (malId: number) => {
|
||||
|
||||
const insertedGenres = await bulkInsertGenresRepository(mediaFullInfo);
|
||||
const insertedStudios = await bulkInsertStudiosRepository(mediaFullInfo);
|
||||
const insertedCharacters = await bulkInsertCharWithVAService(malId);
|
||||
|
||||
const constructMediaPayload = {
|
||||
const constructMediaPayload: Prisma.MediaUpsertArgs["create"] = {
|
||||
title: mediaFullInfo.data.title,
|
||||
titleAlternative: (mediaFullInfo.data
|
||||
.titles as unknown) as Prisma.InputJsonValue,
|
||||
@ -32,6 +34,9 @@ export const bulkInsertAnimeService = async (malId: number) => {
|
||||
studios: {
|
||||
connect: insertedStudios.map((id) => ({ id })),
|
||||
},
|
||||
characters: {
|
||||
connect: insertedCharacters.map(({ id }) => ({ id })),
|
||||
},
|
||||
score: mediaFullInfo.data.score,
|
||||
pictureMedium: mediaFullInfo.data.images.webp.image_url,
|
||||
pictureLarge: mediaFullInfo.data.images.webp.large_image_url,
|
||||
|
||||
@ -30,7 +30,7 @@ export const bulkInsertCharWithVAService = async (malId: number) => {
|
||||
const insertedVAs: { staffId: string; lang: string }[] = [];
|
||||
for (const VAEntries of charEntry.voice_actors) {
|
||||
const insertedVAId = await bulkInsertStaffOrPeopleService(
|
||||
VAEntries.person.mal_id,
|
||||
VAEntries.person,
|
||||
);
|
||||
insertedVAs.push({
|
||||
staffId: insertedVAId.id,
|
||||
|
||||
@ -1,24 +1,14 @@
|
||||
import { SystemAccountId } from "../../../../config/account/system";
|
||||
import { getPeopleAPI } from "../../../../config/apis/people.reference";
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { bulkInsertVoiceActorRepository } from "../../repositories/bulkInsertVoiceActor.repository";
|
||||
import { PeopleInfoResponse } from "../../types/peopleInfo";
|
||||
import { Person } from "../../types/mediaCharWithVAInfo";
|
||||
|
||||
export const bulkInsertStaffOrPeopleService = async (malId: number) => {
|
||||
export const bulkInsertStaffOrPeopleService = async (peopleData: Person) => {
|
||||
try {
|
||||
const { baseURL, getPeopleInfo } = getPeopleAPI(malId);
|
||||
const peopleData = (await fetch(baseURL + getPeopleInfo).then((res) =>
|
||||
res.json(),
|
||||
)) as PeopleInfoResponse;
|
||||
|
||||
return await bulkInsertVoiceActorRepository({
|
||||
malId: peopleData.data.mal_id,
|
||||
name: peopleData.data.name,
|
||||
birthday: peopleData.data.birthday,
|
||||
description: peopleData.data.about,
|
||||
aboutUrl: peopleData.data.url,
|
||||
imageUrl: peopleData.data.images.jpg.image_url,
|
||||
websiteUrl: peopleData.data.website_url,
|
||||
malId: peopleData.mal_id,
|
||||
name: peopleData.name,
|
||||
imageUrl: peopleData.images.jpg.image_url,
|
||||
creatorId: SystemAccountId,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user