mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
update
This commit is contained in:
20
dashboard/server/api/report/customization.ts
Normal file
20
dashboard/server/api/report/customization.ts
Normal 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;
|
||||
|
||||
});
|
||||
26
dashboard/server/api/report/update_customization.post.ts
Normal file
26
dashboard/server/api/report/update_customization.post.ts
Normal 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 }
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user