fix/hero-banner #22

Merged
vivy-agent merged 4 commits from fix/hero-banner into main 2026-03-03 21:59:04 +07:00
8 changed files with 57 additions and 2 deletions
Showing only changes of commit a6b2c77bd1 - Show all commits

View File

@ -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

View File

@ -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");

View File

@ -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?

View File

@ -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");
} }

View 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,
}),
),
);
});
};

View File

@ -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);