41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { PrismaService } from "../../prisma/prisma.service";
|
|
import type { UpdateTenantSettingsDto } from "./dto";
|
|
|
|
@Injectable()
|
|
export class SettingsService {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async get(tenantId: string) {
|
|
const row = await this.prisma.tenantSetting.findUnique({ where: { tenantId } });
|
|
return {
|
|
appName: row?.appName ?? null,
|
|
logoUrl: row?.logoUrl ?? null,
|
|
modules: (row?.modules as any) ?? null
|
|
};
|
|
}
|
|
|
|
async update(tenantId: string, dto: UpdateTenantSettingsDto) {
|
|
const row = await this.prisma.tenantSetting.upsert({
|
|
where: { tenantId },
|
|
create: { tenantId, appName: dto.appName, modules: dto.modules ?? undefined },
|
|
update: { appName: dto.appName, modules: dto.modules ?? undefined }
|
|
});
|
|
return {
|
|
appName: row.appName ?? null,
|
|
logoUrl: row.logoUrl ?? null,
|
|
modules: (row.modules as any) ?? null
|
|
};
|
|
}
|
|
|
|
async setLogo(tenantId: string, logoUrl: string) {
|
|
const row = await this.prisma.tenantSetting.upsert({
|
|
where: { tenantId },
|
|
create: { tenantId, logoUrl },
|
|
update: { logoUrl }
|
|
});
|
|
return { logoUrl: row.logoUrl ?? null };
|
|
}
|
|
}
|
|
|