🐛 fix: move prisma id generator to service and repo

This commit is contained in:
Rafi Arrafif
2026-01-29 02:10:01 +07:00
parent adc38cdfd3
commit e305d955f1
6 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,8 @@
import { generateUUIDv7 } from "./uuidv7";
function createManyWithUUID<T extends { id?: string }>(items: T[]): T[] {
return items.map((i) => ({
...i,
id: i.id ?? generateUUIDv7(),
}));
}

View File

@ -7,6 +7,7 @@ import { bulkInsertStudiosRepository } from "../repositories/bulkInsertStudios.r
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
import { generateSlug } from "../../../helpers/characters/generateSlug";
import { bulkInsertCharWithVAService } from "./internal/bulkInsertCharWithVA.service";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
export const bulkInsertAnimeService = async (malId: number) => {
try {
@ -20,6 +21,7 @@ export const bulkInsertAnimeService = async (malId: number) => {
const insertedCharacters = await bulkInsertCharWithVAService(malId);
const constructMediaPayload: Prisma.MediaUpsertArgs["create"] = {
id: generateUUIDv7(),
title: mediaFullInfo.data.title,
titleAlternative: (mediaFullInfo.data
.titles as unknown) as Prisma.InputJsonValue,

View File

@ -1,5 +1,6 @@
import { SystemAccountId } from "../../../../config/account/system";
import { getContentReferenceAPI } from "../../../../config/apis/media.reference";
import { generateUUIDv7 } from "../../../../helpers/databases/uuidv7";
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { bulkInsertCharactersRepository } from "../../repositories/bulkInsertCharacters.repository";
import { bulkInsertLangVARepository } from "../../repositories/bulkInsertLangVA.repository";
@ -17,6 +18,7 @@ export const bulkInsertCharWithVAService = async (malId: number) => {
for (const charEntry of charactersWithVAData.data) {
// Insert character if not exists
const characterInsertedId = await bulkInsertCharactersRepository({
id: generateUUIDv7(),
malId: charEntry.character.mal_id,
name: charEntry.character.name,
role: charEntry.role,
@ -41,6 +43,7 @@ export const bulkInsertCharWithVAService = async (malId: number) => {
// Link character with inserted VAs
for (const langVA of insertedVAs) {
await bulkInsertLangVARepository({
id: generateUUIDv7(),
language: langVA.lang,
vaId: langVA.staffId,
charId: characterInsertedId.id,

View File

@ -1,4 +1,5 @@
import { SystemAccountId } from "../../../../config/account/system";
import { generateUUIDv7 } from "../../../../helpers/databases/uuidv7";
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { bulkInsertVoiceActorRepository } from "../../repositories/bulkInsertVoiceActor.repository";
import { Person } from "../../types/mediaCharWithVAInfo";
@ -6,6 +7,7 @@ import { Person } from "../../types/mediaCharWithVAInfo";
export const bulkInsertStaffOrPeopleService = async (peopleData: Person) => {
try {
return await bulkInsertVoiceActorRepository({
id: generateUUIDv7(),
malId: peopleData.mal_id,
name: peopleData.name,
imageUrl: peopleData.images.jpg.image_url,