Files
eventsphere/apps/api/src/modules/settings/settings.service.ts
2026-04-25 21:57:48 +01:00

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 };
}
}