🚑 hotfix: update all section that need uuidv7

This commit is contained in:
Rafi Arrafif
2026-01-29 02:58:13 +07:00
parent 467faedf28
commit c5afbb963f
8 changed files with 42 additions and 18 deletions

View File

@ -1,14 +1,18 @@
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { AppError } from "../../../helpers/error/instances/app"; import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection"; import { prisma } from "../../../utils/databases/prisma/connection";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
export const bulkInsertCharactersRepository = async ( export const bulkInsertCharactersRepository = async (
payload: Prisma.CharacterUpsertArgs["create"], payload: Omit<Prisma.CharacterUncheckedCreateInput, "id">,
) => { ) => {
try { try {
return await prisma.character.upsert({ return await prisma.character.upsert({
where: { malId: payload.malId }, where: { malId: payload.malId },
create: payload, create: {
id: generateUUIDv7(),
...payload,
},
update: payload, update: payload,
select: { id: true }, select: { id: true },
}); });

View File

@ -1,4 +1,5 @@
import { generateSlug } from "../../../helpers/characters/generateSlug"; import { generateSlug } from "../../../helpers/characters/generateSlug";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
import { AppError } from "../../../helpers/error/instances/app"; import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection"; import { prisma } from "../../../utils/databases/prisma/connection";
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type"; import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
@ -31,7 +32,10 @@ export const bulkInsertGenresRepository = async (
}; };
const insertedGenre = await prisma.genre.upsert({ const insertedGenre = await prisma.genre.upsert({
where: { slug }, where: { slug },
create: genrePayload, create: {
id: generateUUIDv7(),
...genrePayload,
},
update: genrePayload, update: genrePayload,
select: { id: true }, select: { id: true },
}); });

View File

@ -1,21 +1,25 @@
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { AppError } from "../../../helpers/error/instances/app"; import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection"; import { prisma } from "../../../utils/databases/prisma/connection";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
export const bulkInsertLangVARepository = async ( export const bulkInsertLangVARepository = async (
payload: Prisma.LangVACharUpsertArgs["create"], payload: Omit<Prisma.LangVACharUncheckedCreateInput, "id">,
) => { ) => {
try { try {
const insertedVA = await prisma.langVAChar.upsert({ const insertedVA = await prisma.langVAChar.upsert({
where: { where: {
language_vaId_charId: { language_vaId_charId: {
language: payload.language, language: payload.language as string,
vaId: payload.vaId!, vaId: payload.vaId as string,
charId: payload.charId!, charId: payload.charId as string,
}, },
}, },
create: payload, create: {
update: {}, id: generateUUIDv7(),
...payload,
},
update: payload,
}); });
return insertedVA.id; return insertedVA.id;
} catch (error) { } catch (error) {

View File

@ -1,4 +1,5 @@
import { generateSlug } from "../../../helpers/characters/generateSlug"; import { generateSlug } from "../../../helpers/characters/generateSlug";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
import { AppError } from "../../../helpers/error/instances/app"; import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection"; import { prisma } from "../../../utils/databases/prisma/connection";
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type"; import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
@ -31,7 +32,10 @@ export const bulkInsertStudiosRepository = async (
}; };
const insertedStudio = await prisma.studio.upsert({ const insertedStudio = await prisma.studio.upsert({
where: { slug }, where: { slug },
create: studioPayload, create: {
id: generateUUIDv7(),
...studioPayload,
},
update: studioPayload, update: studioPayload,
select: { id: true }, select: { id: true },
}); });
@ -48,7 +52,10 @@ export const bulkInsertStudiosRepository = async (
}; };
const insertedStudio = await prisma.studio.upsert({ const insertedStudio = await prisma.studio.upsert({
where: { slug }, where: { slug },
create: studioPayload, create: {
id: generateUUIDv7(),
...studioPayload,
},
update: studioPayload, update: studioPayload,
select: { id: true }, select: { id: true },
}); });

View File

@ -1,14 +1,18 @@
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { AppError } from "../../../helpers/error/instances/app"; import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection"; import { prisma } from "../../../utils/databases/prisma/connection";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
export const bulkInsertVoiceActorRepository = async ( export const bulkInsertVoiceActorRepository = async (
payload: Prisma.VoiceActorUpsertArgs["create"], payload: Omit<Prisma.VoiceActorUncheckedCreateInput, "id">,
) => { ) => {
try { try {
return await prisma.voiceActor.upsert({ return await prisma.voiceActor.upsert({
where: { malId: payload.malId }, where: { malId: payload.malId },
create: payload, create: {
id: generateUUIDv7(),
...payload,
},
update: payload, update: payload,
select: { id: true }, select: { id: true },
}); });

View File

@ -2,6 +2,7 @@ import { Prisma } from "@prisma/client";
import { AppError } from "../../../helpers/error/instances/app"; import { AppError } from "../../../helpers/error/instances/app";
import { prisma } from "../../../utils/databases/prisma/connection"; import { prisma } from "../../../utils/databases/prisma/connection";
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type"; import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
/** /**
* Media Payload Construction and Upsert * Media Payload Construction and Upsert
@ -22,13 +23,16 @@ export const InsertMediaRepository = async ({
payload, payload,
}: { }: {
malId: number; malId: number;
payload: Prisma.MediaUpsertArgs["create"]; payload: Omit<Prisma.MediaUncheckedCreateInput, "id">;
}) => { }) => {
try { try {
return await prisma.media.upsert({ return await prisma.media.upsert({
where: { malId }, where: { malId },
update: payload, update: payload,
create: payload, create: {
id: generateUUIDv7(),
...payload,
},
}); });
} catch (error) { } catch (error) {
throw new AppError(500, "Failed to insert media", error); throw new AppError(500, "Failed to insert media", error);

View File

@ -18,7 +18,6 @@ export const bulkInsertCharWithVAService = async (malId: number) => {
for (const charEntry of charactersWithVAData.data) { for (const charEntry of charactersWithVAData.data) {
// Insert character if not exists // Insert character if not exists
const characterInsertedId = await bulkInsertCharactersRepository({ const characterInsertedId = await bulkInsertCharactersRepository({
id: generateUUIDv7(),
malId: charEntry.character.mal_id, malId: charEntry.character.mal_id,
name: charEntry.character.name, name: charEntry.character.name,
role: charEntry.role, role: charEntry.role,
@ -43,7 +42,6 @@ export const bulkInsertCharWithVAService = async (malId: number) => {
// Link character with inserted VAs // Link character with inserted VAs
for (const langVA of insertedVAs) { for (const langVA of insertedVAs) {
await bulkInsertLangVARepository({ await bulkInsertLangVARepository({
id: generateUUIDv7(),
language: langVA.lang, language: langVA.lang,
vaId: langVA.staffId, vaId: langVA.staffId,
charId: characterInsertedId.id, charId: characterInsertedId.id,

View File

@ -7,7 +7,6 @@ import { Person } from "../../types/mediaCharWithVAInfo";
export const bulkInsertStaffOrPeopleService = async (peopleData: Person) => { export const bulkInsertStaffOrPeopleService = async (peopleData: Person) => {
try { try {
return await bulkInsertVoiceActorRepository({ return await bulkInsertVoiceActorRepository({
id: generateUUIDv7(),
malId: peopleData.mal_id, malId: peopleData.mal_id,
name: peopleData.name, name: peopleData.name,
imageUrl: peopleData.images.jpg.image_url, imageUrl: peopleData.images.jpg.image_url,