✨ feat: launch endpoint to insert anime only with malId
This commit is contained in:
@ -21,6 +21,7 @@ Table medias {
|
||||
mediaType MediaType [not null]
|
||||
source String
|
||||
studios studios [not null]
|
||||
characters characters [not null]
|
||||
onDraft Boolean [not null, default: true]
|
||||
uploader users [not null]
|
||||
uploadedBy String [not null]
|
||||
@ -90,6 +91,7 @@ Table characters {
|
||||
deletedAt DateTime
|
||||
createdAt DateTime [default: `now()`, not null]
|
||||
updatedAt DateTime [default: `now()`, not null]
|
||||
medias medias [not null]
|
||||
voice_actors lang_va_char [not null]
|
||||
}
|
||||
|
||||
@ -98,8 +100,8 @@ Table voice_actors {
|
||||
malId Int [unique, not null]
|
||||
name String [not null]
|
||||
birthday DateTime
|
||||
description String [not null]
|
||||
aboutUrl String [not null]
|
||||
description String
|
||||
aboutUrl String
|
||||
imageUrl String
|
||||
websiteUrl String
|
||||
createdBy users [not null]
|
||||
@ -523,6 +525,11 @@ Table MediaStudios {
|
||||
mediasId String [ref: > medias.id]
|
||||
}
|
||||
|
||||
Table MediaCharacters {
|
||||
charactersId String [ref: > characters.id]
|
||||
mediasId String [ref: > medias.id]
|
||||
}
|
||||
|
||||
Table MediaCollections {
|
||||
collectionsId String [ref: > collections.id]
|
||||
mediasId String [ref: > medias.id]
|
||||
|
||||
@ -41,6 +41,7 @@ model Media {
|
||||
mediaType MediaType
|
||||
source String?
|
||||
studios Studio[] @relation("MediaStudios")
|
||||
characters Character[] @relation("MediaCharacters")
|
||||
onDraft Boolean @default(true)
|
||||
uploader User @relation("UserUploadedMedias", fields: [uploadedBy], references: [id])
|
||||
uploadedBy String
|
||||
@ -124,6 +125,7 @@ model Character {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
medias Media[] @relation("MediaCharacters")
|
||||
voice_actors LangVAChar[] @relation("CharVALanguage")
|
||||
@@map("characters")
|
||||
}
|
||||
|
||||
@ -8,8 +8,7 @@ export const bulkInsertAnimeController = async (
|
||||
ctx: Context & { body: { mal_id: number } },
|
||||
) => {
|
||||
try {
|
||||
// const bulkInsertResult = await bulkInsertAnimeService(ctx.body.mal_id);
|
||||
const bulkInsertResult = await bulkInsertCharWithVAService(ctx.body.mal_id);
|
||||
const bulkInsertResult = await bulkInsertAnimeService(ctx.body.mal_id);
|
||||
return returnWriteResponse(
|
||||
ctx.set,
|
||||
201,
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -35,7 +35,7 @@ enum Role {
|
||||
Supporting = "Supporting",
|
||||
}
|
||||
|
||||
interface VoiceActor {
|
||||
export interface VoiceActor {
|
||||
person: Person;
|
||||
language: Language;
|
||||
}
|
||||
@ -47,7 +47,7 @@ enum Language {
|
||||
Spanish = "Spanish",
|
||||
}
|
||||
|
||||
interface Person {
|
||||
export interface Person {
|
||||
mal_id: number;
|
||||
url: string;
|
||||
images: PersonImages;
|
||||
|
||||
Reference in New Issue
Block a user