fix(dto): add class-validator decorators for lead, advisor, and notification endpoints
Deploy Canina / deploy (push) Successful in 2m45s

This commit is contained in:
devops committed 2026-11-07 07:52:39 +00:00
1 parent fae4b570f9
commit 3a0e0f2acc
3 files changed
+188 -32

No files matched your search

+26
View File
@@ -1,19 +1,45 @@
import { Injectable, BadRequestException, NotFoundException, Logger } from '@nestjs/common';
import { IsString, IsNotEmpty, IsOptional, IsBoolean } from 'class-validator';
import { PrismaService } from '../prisma/prisma.service';
import { NotificationsQueueService } from '../notifications/notifications-queue.service';
export class CreateAdvisorDto {
@IsString()
@IsNotEmpty()
name!: string;
@IsString()
@IsNotEmpty()
phone!: string;
@IsString()
@IsOptional()
title?: string;
@IsBoolean()
@IsOptional()
isDefault?: boolean;
@IsBoolean()
@IsOptional()
isActive?: boolean;
}
export class CreateLeadDto {
@IsString()
@IsNotEmpty()
firstName!: string;
@IsString()
@IsNotEmpty()
lastName!: string;
@IsString()
@IsNotEmpty()
phone!: string;
@IsString()
@IsOptional()
productId?: string;
}
@@ -11,10 +11,18 @@ import {
BadRequestException,
} from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { EmailService, SmtpConfig } from './email.service';
import { EmailService } from './email.service';
import { NotificationsQueueService } from './notifications-queue.service';
import { SmsService } from '../common/services/sms.service';
import { PrismaService } from '../prisma/prisma.service';
import {
UpdateEmailConfigDto,
TestSmtpDto,
SendTestEmailDto,
SendTestSmsDto,
ManualSendDto,
CreateTemplateDto,
} from './notifications.dto';
@Controller('admin/notifications')
@UseGuards(JwtAuthGuard)
@@ -60,7 +68,7 @@ export class NotificationsController {
* Update SMTP Email config
*/
@Put('email-config')
async updateEmailConfig(@Body() dto: Partial<SmtpConfig>) {
async updateEmailConfig(@Body() dto: UpdateEmailConfigDto) {
// If password is masked, don't overwrite with dots
if (dto.password && dto.password.includes('•')) {
delete dto.password;
@@ -81,7 +89,7 @@ export class NotificationsController {
* Test SMTP connection live
*/
@Post('test-smtp')
async testSmtp(@Body() customConfig?: Partial<SmtpConfig>) {
async testSmtp(@Body() customConfig?: TestSmtpDto) {
if (customConfig?.password && customConfig.password.includes('•')) {
delete customConfig.password;
}
@@ -98,7 +106,7 @@ export class NotificationsController {
* Send test email
*/
@Post('send-test-email')
async sendTestEmail(@Body() body: { to: string; subject?: string; message?: string }) {
async sendTestEmail(@Body() body: SendTestEmailDto) {
if (!body.to) throw new BadRequestException('آدرس ایمیل مقصد الزامی است.');
const res = await this.emailService.sendMail({
@@ -132,7 +140,7 @@ export class NotificationsController {
* Send test SMS
*/
@Post('send-test-sms')
async sendTestSms(@Body() body: { to: string; message: string }) {
async sendTestSms(@Body() body: SendTestSmsDto) {
if (!body.to || !body.message) {
throw new BadRequestException('شماره موبایل و متن پیام الزامی است.');
}
@@ -150,17 +158,7 @@ export class NotificationsController {
* Manual targeted notification send
*/
@Post('manual-send')
async manualSend(
@Body()
body: {
channel: 'SMS' | 'EMAIL';
targetType: 'single' | 'all_users' | 'custom_list';
recipient?: string;
recipients?: string[];
subject?: string;
content: string;
},
) {
async manualSend(@Body() body: ManualSendDto) {
if (!body.channel || !body.content) {
throw new BadRequestException('کانال ارسال و متن پیام الزامی است.');
}
@@ -275,22 +273,7 @@ export class NotificationsController {
* Create or update notification template
*/
@Post('templates')
async upsertTemplate(
@Body()
dto: {
id?: string;
channel: 'SMS' | 'EMAIL';
event: string;
name: string;
subject?: string;
body: string;
patternCode?: string;
variables?: string[];
recipientType?: string;
customRecipient?: string;
isActive?: boolean;
},
) {
async upsertTemplate(@Body() dto: CreateTemplateDto) {
if (!dto.channel || !dto.event || !dto.name || !dto.body) {
throw new BadRequestException('اطلاعات ضروری قالب ناقص است.');
}
@@ -0,0 +1,147 @@
import { IsString, IsNotEmpty, IsOptional, IsNumber, IsBoolean, IsIn, IsArray } from 'class-validator';
export class UpdateEmailConfigDto {
@IsString()
@IsNotEmpty()
host!: string;
@IsNumber()
port!: number;
@IsBoolean()
secure!: boolean;
@IsString()
@IsNotEmpty()
user!: string;
@IsString()
@IsOptional()
password?: string;
@IsString()
@IsNotEmpty()
from!: string;
}
export class TestSmtpDto {
@IsString()
@IsOptional()
host?: string;
@IsNumber()
@IsOptional()
port?: number;
@IsBoolean()
@IsOptional()
secure?: boolean;
@IsString()
@IsOptional()
user?: string;
@IsString()
@IsOptional()
password?: string;
@IsString()
@IsOptional()
from?: string;
}
export class SendTestEmailDto {
@IsString()
@IsNotEmpty()
to!: string;
@IsString()
@IsOptional()
subject?: string;
@IsString()
@IsOptional()
message?: string;
}
export class SendTestSmsDto {
@IsString()
@IsNotEmpty()
to!: string;
@IsString()
@IsNotEmpty()
message!: string;
}
export class ManualSendDto {
@IsString()
@IsIn(['SMS', 'EMAIL'])
channel!: 'SMS' | 'EMAIL';
@IsString()
@IsIn(['single', 'all_users', 'custom_list'])
targetType!: 'single' | 'all_users' | 'custom_list';
@IsString()
@IsOptional()
recipient?: string;
@IsArray()
@IsOptional()
recipients?: string[];
@IsString()
@IsOptional()
subject?: string;
@IsString()
@IsNotEmpty()
content!: string;
}
export class CreateTemplateDto {
@IsString()
@IsOptional()
id?: string;
@IsString()
@IsIn(['SMS', 'EMAIL'])
channel!: 'SMS' | 'EMAIL';
@IsString()
@IsNotEmpty()
event!: string;
@IsString()
@IsNotEmpty()
name!: string;
@IsString()
@IsOptional()
subject?: string;
@IsString()
@IsNotEmpty()
body!: string;
@IsString()
@IsOptional()
patternCode?: string;
@IsArray()
@IsOptional()
variables?: string[];
@IsString()
@IsOptional()
recipientType?: string;
@IsString()
@IsOptional()
customRecipient?: string;
@IsBoolean()
@IsOptional()
isActive?: boolean;
}