fix/hero-banner #22
@ -513,7 +513,7 @@ Table hero_banner {
|
|||||||
|
|
||||||
Table system_preferences {
|
Table system_preferences {
|
||||||
id String [pk]
|
id String [pk]
|
||||||
key String [not null]
|
key String [unique, not null]
|
||||||
value String [not null]
|
value String [not null]
|
||||||
description String [not null]
|
description String [not null]
|
||||||
deletedAt DateTime
|
deletedAt DateTime
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- A unique constraint covering the columns `[key]` on the table `system_preferences` will be added. If there are existing duplicate values, this will fail.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "system_preferences_key_key" ON "system_preferences"("key");
|
||||||
@ -575,7 +575,7 @@ model HeroBanner {
|
|||||||
|
|
||||||
model SystemPreference {
|
model SystemPreference {
|
||||||
id String @id @db.Uuid
|
id String @id @db.Uuid
|
||||||
key String @db.VarChar(225)
|
key String @db.VarChar(225) @unique
|
||||||
value String @db.VarChar(225)
|
value String @db.VarChar(225)
|
||||||
description String @db.Text
|
description String @db.Text
|
||||||
deletedAt DateTime?
|
deletedAt DateTime?
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { prisma } from "../../src/utils/databases/prisma/connection";
|
import { prisma } from "../../src/utils/databases/prisma/connection";
|
||||||
|
import { systemPreferenceSeed } from "./systemPreference.seed";
|
||||||
import { userRoleSeed } from "./userRole.seed";
|
import { userRoleSeed } from "./userRole.seed";
|
||||||
import { userSystemSeed } from "./userSystem.seed";
|
import { userSystemSeed } from "./userSystem.seed";
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ async function main() {
|
|||||||
|
|
||||||
const userSystemSeedResult = await userSystemSeed();
|
const userSystemSeedResult = await userSystemSeed();
|
||||||
await userRoleSeed(userSystemSeedResult.id);
|
await userRoleSeed(userSystemSeedResult.id);
|
||||||
|
await systemPreferenceSeed();
|
||||||
|
|
||||||
console.log("🌳 All seeds completed");
|
console.log("🌳 All seeds completed");
|
||||||
}
|
}
|
||||||
|
|||||||
35
prisma/seed/systemPreference.seed.ts
Normal file
35
prisma/seed/systemPreference.seed.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
|
||||||
|
import { prisma } from "../../src/utils/databases/prisma/connection";
|
||||||
|
|
||||||
|
export const systemPreferenceSeed = async () => {
|
||||||
|
const preferences: Prisma.SystemPreferenceUpsertArgs["create"][] = [
|
||||||
|
{
|
||||||
|
id: generateUUIDv7(),
|
||||||
|
key: "REGISTRATION_ENABLED",
|
||||||
|
value: process.env.ENABLE_REGISTRATION === "true" ? "true" : "false",
|
||||||
|
description: "Enable or disable user registration",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: generateUUIDv7(),
|
||||||
|
key: "HERO_BANNER_ENABLED",
|
||||||
|
value: process.env.ENABLE_HERO_BANNER === "true" ? "true" : "false",
|
||||||
|
description: "Enable or disable hero banner feature",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await prisma.$transaction(async (tx) => {
|
||||||
|
return await Promise.all(
|
||||||
|
preferences.map(
|
||||||
|
async (pref) =>
|
||||||
|
await tx.systemPreference.upsert({
|
||||||
|
where: {
|
||||||
|
key: pref.key,
|
||||||
|
},
|
||||||
|
update: pref,
|
||||||
|
create: pref,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -1,8 +1,13 @@
|
|||||||
|
import { AppError } from "../../../helpers/error/instances/app";
|
||||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||||
import { findAllActiveHeroBannerRepository } from "../repositories/GET/findAllActiveHeroBanner.repository";
|
import { findAllActiveHeroBannerRepository } from "../repositories/GET/findAllActiveHeroBanner.repository";
|
||||||
|
|
||||||
export const getActiveHeroBannerService = async () => {
|
export const getActiveHeroBannerService = async () => {
|
||||||
try {
|
try {
|
||||||
|
const isHeroBannerEnabled = process.env.ENABLE_HERO_BANNER === "true";
|
||||||
|
if (!isHeroBannerEnabled)
|
||||||
|
throw new AppError(403, "Hero Banner is disabled");
|
||||||
|
|
||||||
return await findAllActiveHeroBannerRepository();
|
return await findAllActiveHeroBannerRepository();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ErrorForwarder(error);
|
ErrorForwarder(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user