🐛 fix: move prisma id generator to service and repo
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
|
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
|
||||||
import { prisma } from "../../src/utils/databases/prisma/connection";
|
import { prisma } from "../../src/utils/databases/prisma/connection";
|
||||||
|
|
||||||
export const userRoleSeed = async (systemId: string) => {
|
export const userRoleSeed = async (systemId: string) => {
|
||||||
const roles = [
|
const roles = [
|
||||||
{
|
{
|
||||||
|
id: generateUUIDv7(),
|
||||||
name: "ADMIN",
|
name: "ADMIN",
|
||||||
description: "Administrator with full access",
|
description: "Administrator with full access",
|
||||||
isSuperadmin: true,
|
isSuperadmin: true,
|
||||||
@ -19,6 +21,7 @@ export const userRoleSeed = async (systemId: string) => {
|
|||||||
createdBy: systemId,
|
createdBy: systemId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: generateUUIDv7(),
|
||||||
name: "USER",
|
name: "USER",
|
||||||
description: "Regular user with limited access",
|
description: "Regular user with limited access",
|
||||||
isSuperadmin: false,
|
isSuperadmin: false,
|
||||||
@ -40,7 +43,7 @@ export const userRoleSeed = async (systemId: string) => {
|
|||||||
roles.map((role) =>
|
roles.map((role) =>
|
||||||
prisma.userRole.upsert({
|
prisma.userRole.upsert({
|
||||||
where: { name: role.name },
|
where: { name: role.name },
|
||||||
update: {},
|
update: role,
|
||||||
create: role,
|
create: role,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
|
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
|
||||||
import { prisma } from "../../src/utils/databases/prisma/connection";
|
import { prisma } from "../../src/utils/databases/prisma/connection";
|
||||||
|
|
||||||
export const userSystemSeed = async () => {
|
export const userSystemSeed = async () => {
|
||||||
const payload = {
|
const payload = {
|
||||||
|
id: generateUUIDv7(),
|
||||||
name: "SYSTEM",
|
name: "SYSTEM",
|
||||||
username: process.env.DEFAULT_ADMIN_USERNAME || "system",
|
username: process.env.DEFAULT_ADMIN_USERNAME || "system",
|
||||||
email: process.env.DEFAULT_ADMIN_EMAIL || "system@example.com",
|
email: process.env.DEFAULT_ADMIN_EMAIL || "system@example.com",
|
||||||
|
|||||||
8
src/helpers/databases/createManyWithUUID.ts
Normal file
8
src/helpers/databases/createManyWithUUID.ts
Normal 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(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ import { bulkInsertStudiosRepository } from "../repositories/bulkInsertStudios.r
|
|||||||
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
|
import { MediaFullInfoResponse } from "../types/mediaFullInfo.type";
|
||||||
import { generateSlug } from "../../../helpers/characters/generateSlug";
|
import { generateSlug } from "../../../helpers/characters/generateSlug";
|
||||||
import { bulkInsertCharWithVAService } from "./internal/bulkInsertCharWithVA.service";
|
import { bulkInsertCharWithVAService } from "./internal/bulkInsertCharWithVA.service";
|
||||||
|
import { generateUUIDv7 } from "../../../helpers/databases/uuidv7";
|
||||||
|
|
||||||
export const bulkInsertAnimeService = async (malId: number) => {
|
export const bulkInsertAnimeService = async (malId: number) => {
|
||||||
try {
|
try {
|
||||||
@ -20,6 +21,7 @@ export const bulkInsertAnimeService = async (malId: number) => {
|
|||||||
const insertedCharacters = await bulkInsertCharWithVAService(malId);
|
const insertedCharacters = await bulkInsertCharWithVAService(malId);
|
||||||
|
|
||||||
const constructMediaPayload: Prisma.MediaUpsertArgs["create"] = {
|
const constructMediaPayload: Prisma.MediaUpsertArgs["create"] = {
|
||||||
|
id: generateUUIDv7(),
|
||||||
title: mediaFullInfo.data.title,
|
title: mediaFullInfo.data.title,
|
||||||
titleAlternative: (mediaFullInfo.data
|
titleAlternative: (mediaFullInfo.data
|
||||||
.titles as unknown) as Prisma.InputJsonValue,
|
.titles as unknown) as Prisma.InputJsonValue,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { SystemAccountId } from "../../../../config/account/system";
|
import { SystemAccountId } from "../../../../config/account/system";
|
||||||
import { getContentReferenceAPI } from "../../../../config/apis/media.reference";
|
import { getContentReferenceAPI } from "../../../../config/apis/media.reference";
|
||||||
|
import { generateUUIDv7 } from "../../../../helpers/databases/uuidv7";
|
||||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
import { bulkInsertCharactersRepository } from "../../repositories/bulkInsertCharacters.repository";
|
import { bulkInsertCharactersRepository } from "../../repositories/bulkInsertCharacters.repository";
|
||||||
import { bulkInsertLangVARepository } from "../../repositories/bulkInsertLangVA.repository";
|
import { bulkInsertLangVARepository } from "../../repositories/bulkInsertLangVA.repository";
|
||||||
@ -17,6 +18,7 @@ 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,
|
||||||
@ -41,6 +43,7 @@ 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,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { SystemAccountId } from "../../../../config/account/system";
|
import { SystemAccountId } from "../../../../config/account/system";
|
||||||
|
import { generateUUIDv7 } from "../../../../helpers/databases/uuidv7";
|
||||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
import { bulkInsertVoiceActorRepository } from "../../repositories/bulkInsertVoiceActor.repository";
|
import { bulkInsertVoiceActorRepository } from "../../repositories/bulkInsertVoiceActor.repository";
|
||||||
import { Person } from "../../types/mediaCharWithVAInfo";
|
import { Person } from "../../types/mediaCharWithVAInfo";
|
||||||
@ -6,6 +7,7 @@ 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user