✨ feat: create bulk insertion for characters
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
|
||||
export const bulkInsertCharactersRepository = async (
|
||||
payload: Prisma.CharacterUpsertArgs["create"],
|
||||
) => {
|
||||
try {
|
||||
return await prisma.character.upsert({
|
||||
where: { malId: payload.malId },
|
||||
create: payload,
|
||||
update: payload,
|
||||
select: { id: true },
|
||||
});
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Failed to bulk insert characters", error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,24 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
|
||||
export const bulkInsertLangVARepository = async (
|
||||
payload: Prisma.LangVACharUpsertArgs["create"],
|
||||
) => {
|
||||
try {
|
||||
const insertedVA = await prisma.langVAChar.upsert({
|
||||
where: {
|
||||
language_vaId_charId: {
|
||||
language: payload.language,
|
||||
vaId: payload.vaId!,
|
||||
charId: payload.charId!,
|
||||
},
|
||||
},
|
||||
create: payload,
|
||||
update: {},
|
||||
});
|
||||
return insertedVA.id;
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Failed to bulk insert VAs", error);
|
||||
}
|
||||
};
|
||||
@ -2,18 +2,17 @@ import { Prisma } from "@prisma/client";
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
|
||||
export const bulkInsertVARepository = async (
|
||||
export const bulkInsertVoiceActorRepository = async (
|
||||
payload: Prisma.VoiceActorUpsertArgs["create"],
|
||||
) => {
|
||||
try {
|
||||
const insertedVA = await prisma.voiceActor.upsert({
|
||||
return await prisma.voiceActor.upsert({
|
||||
where: { malId: payload.malId },
|
||||
create: payload,
|
||||
update: payload,
|
||||
select: { id: true },
|
||||
});
|
||||
return insertedVA.id;
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Failed to bulk insert VAs", error);
|
||||
throw new AppError(500, "Failed to bulk insert voice actor", error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user