2024-12-04 21:26:02 +01:00
|
|
|
import { Body, Controller, HttpCode, HttpStatus, Param, Post } from '@nestjs/common';
|
2024-06-07 11:34:09 -05:00
|
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2025-04-28 10:36:14 -04:00
|
|
|
import {
|
|
|
|
|
NotificationCreateDto,
|
|
|
|
|
NotificationDto,
|
|
|
|
|
TemplateDto,
|
|
|
|
|
TemplateResponseDto,
|
|
|
|
|
TestEmailResponseDto,
|
|
|
|
|
} from 'src/dtos/notification.dto';
|
2024-06-07 11:34:09 -05:00
|
|
|
import { SystemConfigSmtpDto } from 'src/dtos/system-config.dto';
|
|
|
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
2025-04-21 12:53:37 -04:00
|
|
|
import { EmailTemplate } from 'src/repositories/email.repository';
|
2025-04-28 10:36:14 -04:00
|
|
|
import { NotificationAdminService } from 'src/services/notification-admin.service';
|
2024-06-07 11:34:09 -05:00
|
|
|
|
2025-04-21 10:49:26 -04:00
|
|
|
@ApiTags('Notifications (Admin)')
|
2025-04-28 10:36:14 -04:00
|
|
|
@Controller('admin/notifications')
|
2025-04-21 10:49:26 -04:00
|
|
|
export class NotificationAdminController {
|
2025-04-28 10:36:14 -04:00
|
|
|
constructor(private service: NotificationAdminService) {}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@Authenticated({ admin: true })
|
|
|
|
|
createNotification(@Auth() auth: AuthDto, @Body() dto: NotificationCreateDto): Promise<NotificationDto> {
|
|
|
|
|
return this.service.create(auth, dto);
|
|
|
|
|
}
|
2024-06-07 11:34:09 -05:00
|
|
|
|
|
|
|
|
@Post('test-email')
|
2024-08-20 08:50:14 -04:00
|
|
|
@HttpCode(HttpStatus.OK)
|
2024-06-07 11:34:09 -05:00
|
|
|
@Authenticated({ admin: true })
|
2025-04-21 10:49:26 -04:00
|
|
|
sendTestEmailAdmin(@Auth() auth: AuthDto, @Body() dto: SystemConfigSmtpDto): Promise<TestEmailResponseDto> {
|
2024-06-07 11:34:09 -05:00
|
|
|
return this.service.sendTestEmail(auth.user.id, dto);
|
|
|
|
|
}
|
2024-12-04 21:26:02 +01:00
|
|
|
|
|
|
|
|
@Post('templates/:name')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@Authenticated({ admin: true })
|
2025-04-21 10:49:26 -04:00
|
|
|
getNotificationTemplateAdmin(
|
2024-12-04 21:26:02 +01:00
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
|
@Param('name') name: EmailTemplate,
|
|
|
|
|
@Body() dto: TemplateDto,
|
|
|
|
|
): Promise<TemplateResponseDto> {
|
|
|
|
|
return this.service.getTemplate(name, dto.template);
|
|
|
|
|
}
|
2024-06-07 11:34:09 -05:00
|
|
|
}
|