🚑 hotfix: update all section that need uuidv7
This commit is contained in:
@ -1,14 +1,18 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
|
||||
export const bulkInsertCharactersRepository = async (
|
||||
payload: Prisma.CharacterUpsertArgs["create"],
|
||||
payload: Omit<Prisma.CharacterUncheckedCreateInput, "id">,
|
||||
) => {
|
||||
try {
|
||||
return await prisma.character.upsert({
|
||||
where: { malId: payload.malId },
|
||||
create: payload,
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...payload,
|
||||
},
|
||||
update: payload,
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { generateSlug } from "../../../helpers/characters/generateSlug";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
|
||||
@ -31,7 +32,10 @@ export const bulkInsertGenresRepository = async (
|
||||
};
|
||||
const insertedGenre = await prisma.genre.upsert({
|
||||
where: { slug },
|
||||
create: genrePayload,
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...genrePayload,
|
||||
},
|
||||
update: genrePayload,
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
@ -1,21 +1,25 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
|
||||
export const bulkInsertLangVARepository = async (
|
||||
payload: Prisma.LangVACharUpsertArgs["create"],
|
||||
payload: Omit<Prisma.LangVACharUncheckedCreateInput, "id">,
|
||||
) => {
|
||||
try {
|
||||
const insertedVA = await prisma.langVAChar.upsert({
|
||||
where: {
|
||||
language_vaId_charId: {
|
||||
language: payload.language,
|
||||
vaId: payload.vaId!,
|
||||
charId: payload.charId!,
|
||||
language: payload.language as string,
|
||||
vaId: payload.vaId as string,
|
||||
charId: payload.charId as string,
|
||||
},
|
||||
},
|
||||
create: payload,
|
||||
update: {},
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...payload,
|
||||
},
|
||||
update: payload,
|
||||
});
|
||||
return insertedVA.id;
|
||||
} catch (error) {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { generateSlug } from "../../../helpers/characters/generateSlug";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
|
||||
@ -31,7 +32,10 @@ export const bulkInsertStudiosRepository = async (
|
||||
};
|
||||
const insertedStudio = await prisma.studio.upsert({
|
||||
where: { slug },
|
||||
create: studioPayload,
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...studioPayload,
|
||||
},
|
||||
update: studioPayload,
|
||||
select: { id: true },
|
||||
});
|
||||
@ -48,7 +52,10 @@ export const bulkInsertStudiosRepository = async (
|
||||
};
|
||||
const insertedStudio = await prisma.studio.upsert({
|
||||
where: { slug },
|
||||
create: studioPayload,
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...studioPayload,
|
||||
},
|
||||
update: studioPayload,
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
|
||||
export const bulkInsertVoiceActorRepository = async (
|
||||
payload: Prisma.VoiceActorUpsertArgs["create"],
|
||||
payload: Omit<Prisma.VoiceActorUncheckedCreateInput, "id">,
|
||||
) => {
|
||||
try {
|
||||
return await prisma.voiceActor.upsert({
|
||||
where: { malId: payload.malId },
|
||||
create: payload,
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...payload,
|
||||
},
|
||||
update: payload,
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
@ -2,6 +2,7 @@ import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
|
||||
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||
|
||||
/**
|
||||
* Media Payload Construction and Upsert
|
||||
@ -22,13 +23,16 @@ export const InsertMediaRepository = async ({
|
||||
payload,
|
||||
}: {
|
||||
malId: number;
|
||||
payload: Prisma.MediaUpsertArgs["create"];
|
||||
payload: Omit<Prisma.MediaUncheckedCreateInput, "id">;
|
||||
}) => {
|
||||
try {
|
||||
return await prisma.media.upsert({
|
||||
where: { malId },
|
||||
update: payload,
|
||||
create: payload,
|
||||
create: {
|
||||
id: generateUUIDv7(),
|
||||
...payload,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Failed to insert media", error);
|
||||
|
||||
@ -18,7 +18,6 @@ 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,
|
||||
@ -43,7 +42,6 @@ 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,
|
||||
|
||||
@ -7,7 +7,6 @@ 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,
|
||||
|
||||
Reference in New Issue
Block a user