import { Controller, Get, Patch, Body, UseGuards, Param, Res } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { Response } from 'express'; import { SettingsService } from './settings.service'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; @ApiTags('Settings') @Controller('settings') export class SettingsController { constructor(private settings: SettingsService) {} @Get() getGlobal() { return this.settings.getGlobal(); } @Patch() @UseGuards(JwtAuthGuard) @ApiBearerAuth() updateGlobal(@Body() body: Record) { return this.settings.updateGlobal(body); } // Policies admin (protected) @Get('policies') @UseGuards(JwtAuthGuard) @ApiBearerAuth() getPolicies() { return this.settings.getPolicies(); } @Patch('policies/:key') @UseGuards(JwtAuthGuard) @ApiBearerAuth() updatePolicy(@Param('key') key: 'privacy' | 'terms', @Body() body: { content: string }) { return this.settings.updatePolicy(key, body.content); } // Public policy pages @Get('policy/:key') async getPublicPolicy(@Param('key') key: string, @Res() res: Response) { const content = await this.settings.getPolicy(key); const titles: Record = { privacy: 'Politica de Privacidad', terms: 'Terminos y Condiciones', }; const title = titles[key] || 'Politica'; if (!content) { return res.status(404).send(`

${title}

No disponible aun.

`); } const html = ` ${title} - ProsApp
ProsApp

${title}

${content.replace(//g, '>')}
`; res.setHeader('Content-Type', 'text/html; charset=utf-8'); return res.send(html); } }