import {prisma} from "@/common/lib/prisma"; import {handlePrismaError} from "@/common/utils/functions"; import {Controller} from "@/core/controller/main.controller"; export interface ConfigFormItem { key: string; value: string; description?: string; } class ConfigsServiceClass extends Controller { async init() { try { await prisma.panelConfig.createMany({ data: [ { key: "email.enabled", value: "true", type: "BOOLEAN", description: "Enable/disable email sending module", }, { key: "sms.enabled", value: "false", type: "BOOLEAN", description: "Enable/disable SMS sending module", }, { key: "upload.document.maxSize", value: "5242880", type: "NUMBER", description: "Max upload Documents size in bytes (5MB)", }, { key: "upload.document.formats", value: "[application/pdf,application/zip,application/x-rar-compressed,application/dicom,text/plain]", type: "STRING_ARRAY", description: "Max upload size in bytes (5MB)", }, { key: "upload.profile.maxSize", value: "5242880", type: "NUMBER", description: "Max upload profile picture size in bytes (5MB)", }, { key: "upload.profile.formats", value: "[png,jpg,webp]", type: "STRING_ARRAY", description: "Max upload profile picture size in bytes (5MB)", }, ], }); } catch (error) { handlePrismaError(error); } } async update(data: ConfigFormItem[]) { // console.log(data); try { await prisma.$transaction( data.map((item) => prisma.panelConfig.update({ where: {key: item.key}, data: { value: item.value, description: item.description, }, }) ) ); } catch (error) { handlePrismaError(error); } } async getAll() { try { const data = await prisma.panelConfig.findMany(); return data; } catch (error) { handlePrismaError(error); } } } const ConfigsService = new ConfigsServiceClass(); export default ConfigsService;