wip: create new req endpoint to get characters data
This commit is contained in:
@ -4,6 +4,6 @@ export const getContentReferenceAPI = (malId: number) => {
|
|||||||
return {
|
return {
|
||||||
baseURL,
|
baseURL,
|
||||||
getMediaFullInfo: `/anime/${malId}/full`,
|
getMediaFullInfo: `/anime/${malId}/full`,
|
||||||
getMediaCharactersWithVA: `/anime/${malId}/characters`,
|
getMediaCharacters: `/anime/${malId}/characters`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
import {AppError} from "../../../helpers/error/instances/app";
|
||||||
|
|
||||||
|
export const bulkInsertMediaCharacterRepository = async (animeMalId: number) => {
|
||||||
|
try {
|
||||||
|
return animeMalId
|
||||||
|
} catch (error) {
|
||||||
|
throw new AppError(500, "Failed to bulk insert media characters", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -143,7 +143,11 @@ export const InsertMediaRepository = async ({ payload }: { payload: MediaFullInf
|
|||||||
});
|
});
|
||||||
|
|
||||||
await bulkInsertMediaProducerStudioLicensorRepository(tx, media.id, producerPayload);
|
await bulkInsertMediaProducerStudioLicensorRepository(tx, media.id, producerPayload);
|
||||||
return media.id;
|
return {
|
||||||
|
id: media.id,
|
||||||
|
mal_id: payload.mal_id,
|
||||||
|
name: payload.title,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -1,16 +1,23 @@
|
|||||||
import {ErrorForwarder} from "../../../../helpers/error/instances/forwarder";
|
import {ErrorForwarder} from "../../../../helpers/error/instances/forwarder";
|
||||||
import {InsertMediaRepository} from "../../repositories/bulkinsertMedia.repository";
|
import {InsertMediaRepository} from "../../repositories/bulkinsertMedia.repository";
|
||||||
import {getContentReferenceAPI} from "../../../../config/apis/jikan/media.reference";
|
import {getContentReferenceAPI} from "../../../../config/apis/jikan/media.reference";
|
||||||
|
import {bulkInsertMediaCharacterRepository} from "../../repositories/bulkInsertMediaCharacter.repository";
|
||||||
import {MediaFullInfoResponse} from "../../types/mediaFullInfo.type";
|
import {MediaFullInfoResponse} from "../../types/mediaFullInfo.type";
|
||||||
|
import {MediaCharacters} from "../../types/mediaCharacters";
|
||||||
|
|
||||||
export const bulkInsertAnimeService = async (malId: number) => {
|
export const bulkInsertAnimeService = async (malId: number) => {
|
||||||
try {
|
try {
|
||||||
const { baseURL, getMediaFullInfo } = getContentReferenceAPI(malId);
|
const {baseURL, getMediaFullInfo, getMediaCharacters} = getContentReferenceAPI(malId);
|
||||||
const mediaFullInfo = (await fetch(baseURL + getMediaFullInfo).then((res) => res.json())) as MediaFullInfoResponse;
|
const mediaFullInfo = (await fetch(baseURL + getMediaFullInfo).then((res) => res.json())) as MediaFullInfoResponse;
|
||||||
|
|
||||||
return await InsertMediaRepository({
|
const insertedMedia = await InsertMediaRepository({
|
||||||
payload: mediaFullInfo.data,
|
payload: mediaFullInfo.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// await bulkInsertMediaCharacterRepository(insertedMedia.mal_id)
|
||||||
|
const mediaChar = await fetch(baseURL + getMediaCharacters).then((res) => res.json()) as MediaCharacters;
|
||||||
|
return mediaChar;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ErrorForwarder(error);
|
ErrorForwarder(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { getContentReferenceAPI } from "../../../../config/apis/jikan/media.refe
|
|||||||
import {ErrorForwarder} from "../../../../helpers/error/instances/forwarder";
|
import {ErrorForwarder} from "../../../../helpers/error/instances/forwarder";
|
||||||
import {bulkInsertCharactersRepository} from "../../repositories/bulkInsertCharacters.repository";
|
import {bulkInsertCharactersRepository} from "../../repositories/bulkInsertCharacters.repository";
|
||||||
import {bulkInsertLangVARepository} from "../../repositories/bulkInsertLangVA.repository";
|
import {bulkInsertLangVARepository} from "../../repositories/bulkInsertLangVA.repository";
|
||||||
import { MediaCharWithVAInfo } from "../../types/mediaCharWithVAInfo";
|
import {MediaCharWithVAInfo} from "../../types/mediaCharacters";
|
||||||
import {bulkInsertStaffOrPeopleService} from "./bulkInsertStaffOrPeople.service";
|
import {bulkInsertStaffOrPeopleService} from "./bulkInsertStaffOrPeople.service";
|
||||||
|
|
||||||
export const bulkInsertCharWithVAService = async (malId: number) => {
|
export const bulkInsertCharWithVAService = async (malId: number) => {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import {SystemAccountId} from "../../../../config/account/system";
|
import {SystemAccountId} from "../../../../config/account/system";
|
||||||
import {ErrorForwarder} from "../../../../helpers/error/instances/forwarder";
|
import {ErrorForwarder} from "../../../../helpers/error/instances/forwarder";
|
||||||
import {bulkInsertVoiceActorRepository} from "../../repositories/bulkInsertVoiceActor.repository";
|
import {bulkInsertVoiceActorRepository} from "../../repositories/bulkInsertVoiceActor.repository";
|
||||||
import { Person } from "../../types/mediaCharWithVAInfo";
|
import {Person} from "../../types/mediaCharacters";
|
||||||
|
|
||||||
export const bulkInsertStaffOrPeopleService = async (peopleData: Person) => {
|
export const bulkInsertStaffOrPeopleService = async (peopleData: Person) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,59 +0,0 @@
|
|||||||
export interface MediaCharWithVAInfo {
|
|
||||||
data: Datum[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Datum {
|
|
||||||
character: Character;
|
|
||||||
role: Role;
|
|
||||||
favorites: number;
|
|
||||||
voice_actors: VoiceActor[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Character {
|
|
||||||
mal_id: number;
|
|
||||||
url: string;
|
|
||||||
images: CharacterImages;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CharacterImages {
|
|
||||||
jpg: Jpg;
|
|
||||||
webp: Webp;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Jpg {
|
|
||||||
image_url: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Webp {
|
|
||||||
image_url: string;
|
|
||||||
small_image_url: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Role {
|
|
||||||
Main = "Main",
|
|
||||||
Supporting = "Supporting",
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface VoiceActor {
|
|
||||||
person: Person;
|
|
||||||
language: Language;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Language {
|
|
||||||
English = "English",
|
|
||||||
Japanese = "Japanese",
|
|
||||||
PortugueseBR = "Portuguese (BR)",
|
|
||||||
Spanish = "Spanish",
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Person {
|
|
||||||
mal_id: number;
|
|
||||||
url: string;
|
|
||||||
images: PersonImages;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PersonImages {
|
|
||||||
jpg: Jpg;
|
|
||||||
}
|
|
||||||
48
src/modules/internal/types/mediaCharacters.ts
Normal file
48
src/modules/internal/types/mediaCharacters.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
interface StaffVA {
|
||||||
|
mal_id: number;
|
||||||
|
url: string;
|
||||||
|
images: {
|
||||||
|
jpg: {
|
||||||
|
image_url: string;
|
||||||
|
},
|
||||||
|
webp: {
|
||||||
|
image_url: string;
|
||||||
|
small_image_url: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface voiceActor {
|
||||||
|
person: StaffVA;
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Character {
|
||||||
|
mal_id: number;
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
images: {
|
||||||
|
jpg: {
|
||||||
|
image_url: string;
|
||||||
|
},
|
||||||
|
webp: {
|
||||||
|
image_url: string;
|
||||||
|
small_image_url: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Role {
|
||||||
|
Main = "Main",
|
||||||
|
Supporting = "Supporting",
|
||||||
|
Background = "Background",
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MediaChar {
|
||||||
|
character: Character;
|
||||||
|
role: Role;
|
||||||
|
favorites: number;
|
||||||
|
voice_actors: voiceActor[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type MediaCharacters = Array<MediaChar>;
|
||||||
Reference in New Issue
Block a user