mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 17:24:48 +10:00
af08472e45
* Adds settings for server name and logo * Implements ApplicationLogo and replaces site name based on settings * Refactors component for changing the company logo * Removes unused variable * Uses message instead of statusMessage * Replaces favicon with logo if set
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import aclManager from "~/server/internal/acls";
|
|
import prisma from "~/server/internal/db/database";
|
|
import objectHandler from "~/server/internal/objects";
|
|
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
|
|
|
|
export default defineEventHandler(async (h3) => {
|
|
const allowed = await aclManager.allowSystemACL(h3, ["company:update"]);
|
|
if (!allowed) throw createError({ statusCode: 403 });
|
|
|
|
const companyId = getRouterParam(h3, "id")!;
|
|
const company = await prisma.company.findUnique({
|
|
where: {
|
|
id: companyId,
|
|
},
|
|
});
|
|
|
|
if (!company)
|
|
throw createError({ statusCode: 400, statusMessage: "Invalid company id" });
|
|
|
|
const result = await handleFileUpload(h3, {}, ["internal:read"], 1);
|
|
if (!result)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "File upload required (multipart form)",
|
|
});
|
|
|
|
const [ids, , pull, dump] = result;
|
|
const id = ids.at(0);
|
|
if (!id)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "Upload at least one file.",
|
|
});
|
|
|
|
await objectHandler.deleteAsSystem(company.mLogoObjectId);
|
|
const { count } = await prisma.company.updateMany({
|
|
where: {
|
|
id: companyId,
|
|
},
|
|
data: {
|
|
mLogoObjectId: id,
|
|
},
|
|
});
|
|
if (count == 0) {
|
|
dump();
|
|
throw createError({ statusCode: 404, message: "Company not found" });
|
|
}
|
|
|
|
await pull();
|
|
|
|
return { id: id };
|
|
});
|