import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; @Injectable() export class SettingsService { constructor(private prisma: PrismaService) {} async getAll(): Promise> { const settings = await this.prisma.setting.findMany(); return Object.fromEntries(settings.map((s) => [s.key, s.value])); } async get(key: string): Promise { const setting = await this.prisma.setting.findUnique({ where: { key } }); return setting?.value ?? null; } async set(key: string, value: string) { return this.prisma.setting.upsert({ where: { key }, update: { value }, create: { key, value }, }); } async setMany(settings: Record) { const ops = Object.entries(settings).map(([key, value]) => this.prisma.setting.upsert({ where: { key }, update: { value }, create: { key, value } }), ); return this.prisma.$transaction(ops); } async remove(key: string) { return this.prisma.setting.delete({ where: { key } }).catch(() => null); } }