diff --git a/prisma/dbml/schema.dbml b/prisma/dbml/schema.dbml index b14d343..26fb935 100644 --- a/prisma/dbml/schema.dbml +++ b/prisma/dbml/schema.dbml @@ -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] diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 11407cc..681a94b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -23,26 +23,27 @@ generator dbml { //// Prisma Model //// model Media { - id String @id @default(uuid()) - title String @db.Text + id String @id @default(uuid()) + title String @db.Text titleAlternative Json - slug String @db.Text @unique - malId Int? @unique - pictureMedium String @db.Text - pictureLarge String @db.Text - genres Genre[] @relation("MediaGenres") - country Country @default(JP) - score Decimal @db.Decimal(4, 2) @default(0.00) + slug String @db.Text @unique + malId Int? @unique + pictureMedium String @db.Text + pictureLarge String @db.Text + genres Genre[] @relation("MediaGenres") + country Country @default(JP) + score Decimal @db.Decimal(4, 2) @default(0.00) status String startAiring DateTime? endAiring DateTime? - synopsis String @db.Text + synopsis String @db.Text ageRating String mediaType MediaType source String? - studios Studio[] @relation("MediaStudios") - onDraft Boolean @default(true) - uploader User @relation("UserUploadedMedias", fields: [uploadedBy], references: [id]) + studios Studio[] @relation("MediaStudios") + characters Character[] @relation("MediaCharacters") + onDraft Boolean @default(true) + uploader User @relation("UserUploadedMedias", fields: [uploadedBy], references: [id]) uploadedBy String deletedAt DateTime? createdAt DateTime @default(now()) @@ -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") } @@ -133,8 +135,8 @@ model VoiceActor { malId Int @unique name String birthday DateTime? - description String @db.Text - aboutUrl String + description String? @db.Text + aboutUrl String? imageUrl String? websiteUrl String? createdBy User @relation("UserCreatedVoiceActors", fields: [creatorId], references: [id]) diff --git a/src/modules/internal/controllers/bulkInsertAnime.controller.ts b/src/modules/internal/controllers/bulkInsertAnime.controller.ts index 6fe2267..831f553 100644 --- a/src/modules/internal/controllers/bulkInsertAnime.controller.ts +++ b/src/modules/internal/controllers/bulkInsertAnime.controller.ts @@ -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, diff --git a/src/modules/internal/services/bulkInsertAnime.service.ts b/src/modules/internal/services/bulkInsertAnime.service.ts index 8379125..531802e 100644 --- a/src/modules/internal/services/bulkInsertAnime.service.ts +++ b/src/modules/internal/services/bulkInsertAnime.service.ts @@ -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, diff --git a/src/modules/internal/services/internal/bulkInsertCharWithVA.service.ts b/src/modules/internal/services/internal/bulkInsertCharWithVA.service.ts index c5aea7f..bd9d2e0 100644 --- a/src/modules/internal/services/internal/bulkInsertCharWithVA.service.ts +++ b/src/modules/internal/services/internal/bulkInsertCharWithVA.service.ts @@ -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, diff --git a/src/modules/internal/services/internal/bulkInsertStaffOrPeople.service.ts b/src/modules/internal/services/internal/bulkInsertStaffOrPeople.service.ts index df46384..0f6ef4c 100644 --- a/src/modules/internal/services/internal/bulkInsertStaffOrPeople.service.ts +++ b/src/modules/internal/services/internal/bulkInsertStaffOrPeople.service.ts @@ -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) { diff --git a/src/modules/internal/types/mediaCharWithVAInfo.ts b/src/modules/internal/types/mediaCharWithVAInfo.ts index 30e52e8..b1f3091 100644 --- a/src/modules/internal/types/mediaCharWithVAInfo.ts +++ b/src/modules/internal/types/mediaCharWithVAInfo.ts @@ -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;