🐛 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

@ -1,8 +1,10 @@
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
import { prisma } from "../../src/utils/databases/prisma/connection";
export const userRoleSeed = async (systemId: string) => {
const roles = [
{
id: generateUUIDv7(),
name: "ADMIN",
description: "Administrator with full access",
isSuperadmin: true,
@ -19,6 +21,7 @@ export const userRoleSeed = async (systemId: string) => {
createdBy: systemId,
},
{
id: generateUUIDv7(),
name: "USER",
description: "Regular user with limited access",
isSuperadmin: false,
@ -40,7 +43,7 @@ export const userRoleSeed = async (systemId: string) => {
roles.map((role) =>
prisma.userRole.upsert({
where: { name: role.name },
update: {},
update: role,
create: role,
}),
),

View File

@ -1,7 +1,9 @@
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
import { prisma } from "../../src/utils/databases/prisma/connection";
export const userSystemSeed = async () => {
const payload = {
id: generateUUIDv7(),
name: "SYSTEM",
username: process.env.DEFAULT_ADMIN_USERNAME || "system",
email: process.env.DEFAULT_ADMIN_EMAIL || "system@example.com",

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,