26 lines
803 B
TypeScript
26 lines
803 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
import { UpdateBillingSettingsDto } from './dto/update-billing-settings.dto';
|
|
|
|
@Injectable()
|
|
export class BillingService {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async getSettings(tenantId: string) {
|
|
let settings = await this.prisma.billingSetting.findUnique({ where: { tenantId } });
|
|
if (!settings) {
|
|
settings = await this.prisma.billingSetting.create({ data: { tenantId } });
|
|
}
|
|
return settings;
|
|
}
|
|
|
|
async updateSettings(tenantId: string, dto: UpdateBillingSettingsDto) {
|
|
await this.prisma.billingSetting.upsert({
|
|
where: { tenantId },
|
|
create: { tenantId, ...dto },
|
|
update: dto,
|
|
});
|
|
return this.getSettings(tenantId);
|
|
}
|
|
}
|