This commit is contained in:
Emily
2025-04-24 17:36:23 +02:00
parent a9bbc58ad1
commit eb954cac6c
17 changed files with 358 additions and 158 deletions

View File

@@ -0,0 +1,20 @@
import { ReportCustomizationModel, TReportCustomization } from "~/shared/schema/report/ReportCustomizationSchema";
export default defineEventHandler(async event => {
const data = await getRequestData(event, []);
if (!data) return;
const customization = await ReportCustomizationModel.findOne({ project_id: data.project_id });
if (!customization) return {
_id: '' as any,
project_id: data.project_id.toString() as any,
bg: 'black',
logo: undefined,
text: 'white'
} as TReportCustomization;
return customization.toJSON() as TReportCustomization;
});

View File

@@ -0,0 +1,26 @@
import z from 'zod';
import { ReportCustomizationModel } from "~/shared/schema/report/ReportCustomizationSchema";
const ZUpdateCustomizationBody = z.object({
logo: z.string().optional(),
bg: z.enum(['black', 'white'])
})
export default defineEventHandler(async event => {
const data = await getRequestData(event, []);
if (!data) return;
const body = await readBody(event);
const bodyData = ZUpdateCustomizationBody.parse(body);
await ReportCustomizationModel.updateOne({ project_id: data.project_id }, {
logo: bodyData.logo,
bg: bodyData.bg,
text: bodyData.bg === 'white' ? 'black' : 'white'
}, { upsert: true });
return { ok: true }
});