- Backend: GET /settings/maps-key (public) + PATCH /settings/maps (protected) - Admin: sección para guardar/ver estado de la Maps API key - Flutter web carga la key dinámicamente desde el backend Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
const POLICY_KEYS = ['privacy', 'terms'] as const;
|
|
type PolicyKey = typeof POLICY_KEYS[number];
|
|
|
|
@Injectable()
|
|
export class SettingsService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async getGlobal() {
|
|
const setting = await this.prisma.settings.findUnique({ where: { key: 'global' } });
|
|
return setting?.value;
|
|
}
|
|
|
|
async updateGlobal(value: Record<string, any>) {
|
|
return this.prisma.settings.upsert({
|
|
where: { key: 'global' },
|
|
create: { key: 'global', value },
|
|
update: { value },
|
|
});
|
|
}
|
|
|
|
async getPolicy(key: string): Promise<string | null> {
|
|
const setting = await this.prisma.settings.findUnique({ where: { key: `policy_${key}` } });
|
|
return (setting?.value as any)?.content ?? null;
|
|
}
|
|
|
|
async updatePolicy(key: PolicyKey, content: string) {
|
|
return this.prisma.settings.upsert({
|
|
where: { key: `policy_${key}` },
|
|
create: { key: `policy_${key}`, value: { content } },
|
|
update: { value: { content } },
|
|
});
|
|
}
|
|
|
|
async getPolicies() {
|
|
const [privacy, terms] = await Promise.all([
|
|
this.getPolicy('privacy'),
|
|
this.getPolicy('terms'),
|
|
]);
|
|
return { privacy, terms };
|
|
}
|
|
|
|
async getMapsKey(): Promise<string | null> {
|
|
const setting = await this.prisma.settings.findUnique({ where: { key: 'maps_config' } });
|
|
return (setting?.value as any)?.api_key ?? null;
|
|
}
|
|
|
|
async saveMapsKey(api_key: string) {
|
|
return this.prisma.settings.upsert({
|
|
where: { key: 'maps_config' },
|
|
create: { key: 'maps_config', value: { api_key } },
|
|
update: { value: { api_key } },
|
|
});
|
|
}
|
|
}
|