import { Controller, Get, Patch, Post, Body, UseGuards } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { IsString } from 'class-validator'; import { SmsService } from './sms.service'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; class SaveConfigDto { @IsString() api_key: string; } class TestSmsDto { @IsString() numero: string; @IsString() mensaje: string; } @ApiTags('SMS') @Controller('sms') @UseGuards(JwtAuthGuard) @ApiBearerAuth() export class SmsController { constructor(private sms: SmsService) {} @Get('config') async getConfig() { const config = await this.sms.getConfig(); if (!config?.api_key) return { configured: false, api_key_preview: '' }; const k = config.api_key; const preview = k.length > 8 ? `${k.slice(0, 8)}••••••••${k.slice(-4)}` : '••••••••'; return { configured: true, api_key_preview: preview }; } @Patch('config') async saveConfig(@Body() dto: SaveConfigDto) { await this.sms.saveConfig(dto.api_key); return { ok: true }; } @Post('test') test(@Body() dto: TestSmsDto) { return this.sms.send(dto.numero, dto.mensaje); } }