Initial MRP foundation scaffold
This commit is contained in:
72
server/src/modules/settings/service.ts
Normal file
72
server/src/modules/settings/service.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import type { CompanyProfileDto, CompanyProfileInput } from "@mrp/shared";
|
||||
|
||||
import { prisma } from "../../lib/prisma.js";
|
||||
|
||||
type CompanyProfileRecord = Awaited<ReturnType<typeof prisma.companyProfile.findFirstOrThrow>>;
|
||||
|
||||
function mapCompanyProfile(profile: CompanyProfileRecord): CompanyProfileDto {
|
||||
return {
|
||||
id: profile.id,
|
||||
companyName: profile.companyName,
|
||||
legalName: profile.legalName,
|
||||
email: profile.email,
|
||||
phone: profile.phone,
|
||||
website: profile.website,
|
||||
taxId: profile.taxId,
|
||||
addressLine1: profile.addressLine1,
|
||||
addressLine2: profile.addressLine2,
|
||||
city: profile.city,
|
||||
state: profile.state,
|
||||
postalCode: profile.postalCode,
|
||||
country: profile.country,
|
||||
theme: {
|
||||
primaryColor: profile.primaryColor,
|
||||
accentColor: profile.accentColor,
|
||||
surfaceColor: profile.surfaceColor,
|
||||
fontFamily: profile.fontFamily,
|
||||
logoFileId: profile.logoFileId,
|
||||
},
|
||||
logoUrl: profile.logoFileId ? `/api/v1/files/${profile.logoFileId}/content` : null,
|
||||
updatedAt: profile.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
export async function getActiveCompanyProfile() {
|
||||
return mapCompanyProfile(
|
||||
await prisma.companyProfile.findFirstOrThrow({
|
||||
where: { isActive: true },
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateActiveCompanyProfile(payload: CompanyProfileInput) {
|
||||
const current = await prisma.companyProfile.findFirstOrThrow({
|
||||
where: { isActive: true },
|
||||
});
|
||||
|
||||
const profile = await prisma.companyProfile.update({
|
||||
where: { id: current.id },
|
||||
data: {
|
||||
companyName: payload.companyName,
|
||||
legalName: payload.legalName,
|
||||
email: payload.email,
|
||||
phone: payload.phone,
|
||||
website: payload.website,
|
||||
taxId: payload.taxId,
|
||||
addressLine1: payload.addressLine1,
|
||||
addressLine2: payload.addressLine2,
|
||||
city: payload.city,
|
||||
state: payload.state,
|
||||
postalCode: payload.postalCode,
|
||||
country: payload.country,
|
||||
primaryColor: payload.theme.primaryColor,
|
||||
accentColor: payload.theme.accentColor,
|
||||
surfaceColor: payload.theme.surfaceColor,
|
||||
fontFamily: payload.theme.fontFamily,
|
||||
logoFileId: payload.theme.logoFileId,
|
||||
},
|
||||
});
|
||||
|
||||
return mapCompanyProfile(profile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user