feat: SMTP config en DB, historial mensajes, JWT 90d, email OTP con Prisma
- schema.prisma: modelo message_logs (channel, recipient, body, status, error) - email-otp.service.ts: lee config SMTP desde DB (settings.smtp_config), registra log en message_logs - sms.service.ts: registra log en message_logs tras cada envío (éxito y error) - auth.module.ts: agrega PrismaModule, JWT expira en 90d - settings.controller.ts: GET/PATCH /settings/smtp + GET /settings/message-logs - settings.service.ts: método getMessageLogs con paginación y filtro por canal - settings.module.ts: importa AuthModule + EmailOtpService Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
a9b5e413e3
commit
522adc3b74
@@ -1,13 +1,14 @@
|
||||
import { Controller, Get, Patch, Body, UseGuards, Param, Res } from '@nestjs/common';
|
||||
import { Controller, Get, Patch, Body, UseGuards, Param, Res, Query } 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';
|
||||
import { EmailOtpService } from '../auth/email-otp.service';
|
||||
|
||||
@ApiTags('Settings')
|
||||
@Controller('settings')
|
||||
export class SettingsController {
|
||||
constructor(private settings: SettingsService) {}
|
||||
constructor(private settings: SettingsService, private emailOtp: EmailOtpService) {}
|
||||
|
||||
@Get()
|
||||
getGlobal() { return this.settings.getGlobal(); }
|
||||
@@ -29,6 +30,27 @@ export class SettingsController {
|
||||
return this.settings.updatePolicy(key, body.content);
|
||||
}
|
||||
|
||||
// SMTP config
|
||||
@Get('smtp')
|
||||
@UseGuards(JwtAuthGuard) @ApiBearerAuth()
|
||||
async getSmtp() {
|
||||
const cfg = await this.emailOtp.getSmtpConfig();
|
||||
return cfg ?? {};
|
||||
}
|
||||
|
||||
@Patch('smtp')
|
||||
@UseGuards(JwtAuthGuard) @ApiBearerAuth()
|
||||
saveSmtp(@Body() body: { host: string; port: string; user: string; pass: string; from?: string }) {
|
||||
return this.emailOtp.saveSmtpConfig(body);
|
||||
}
|
||||
|
||||
// Message logs
|
||||
@Get('message-logs')
|
||||
@UseGuards(JwtAuthGuard) @ApiBearerAuth()
|
||||
getMessageLogs(@Query('page') page = '1', @Query('limit') limit = '50', @Query('channel') channel?: string) {
|
||||
return this.settings.getMessageLogs(+page, +limit, channel);
|
||||
}
|
||||
|
||||
// Maps key
|
||||
@Get('maps-key')
|
||||
async getMapsKey() {
|
||||
|
||||
Reference in New Issue
Block a user