fix(build): resolve linter and tsconfig project service errors, guarantee dist/main existence in start-dev
Deploy Canina / deploy (push) Has been cancelled

This commit is contained in:
parsa aghaei committed 2026-08-18 20:23:59 +03:30
1 parent a291fa0c4a
commit 6362750dea
50 files changed
+12128 -10959

No files matched your search

+1 -4
View File
@@ -66,10 +66,7 @@ export class AdminController {
@Put('users/:id')
@ApiOperation({ summary: 'ویرایش مشخصات کامل کاربر' })
async updateUser(
@Param('id') id: string,
@Body() dto: UpdateUserDto,
) {
async updateUser(@Param('id') id: string, @Body() dto: UpdateUserDto) {
const user = await this.adminService.updateUser(id, dto);
return {
success: true,
+84 -27
View File
@@ -119,9 +119,20 @@ export class AdminService {
}
}
const sortField = (query.sortBy && typeof query.sortBy === 'string' && ['createdAt', 'firstName', 'lastName', 'mobile', 'email', 'role', 'walletBalance'].includes(query.sortBy))
? query.sortBy
: 'createdAt';
const sortField =
query.sortBy &&
typeof query.sortBy === 'string' &&
[
'createdAt',
'firstName',
'lastName',
'mobile',
'email',
'role',
'walletBalance',
].includes(query.sortBy)
? query.sortBy
: 'createdAt';
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
const [data, total] = await Promise.all([
@@ -167,7 +178,9 @@ export class AdminService {
where: { mobile },
});
if (existingMobile) {
throw new BadRequestException('کاربری با این شماره موبایل قبلاً در سیستم ثبت شده است');
throw new BadRequestException(
'کاربری با این شماره موبایل قبلاً در سیستم ثبت شده است',
);
}
if (dto.email) {
@@ -175,12 +188,16 @@ export class AdminService {
where: { email: dto.email.trim().toLowerCase() },
});
if (existingEmail) {
throw new BadRequestException('کاربری با این آدرس ایمیل قبلاً در سیستم ثبت شده است');
throw new BadRequestException(
'کاربری با این آدرس ایمیل قبلاً در سیستم ثبت شده است',
);
}
}
const passwordToHash = dto.password?.trim();
const hashedPassword = passwordToHash ? await bcrypt.hash(passwordToHash, 10) : '';
const hashedPassword = passwordToHash
? await bcrypt.hash(passwordToHash, 10)
: '';
return this.prisma.user.create({
data: {
@@ -200,7 +217,9 @@ export class AdminService {
async updateUser(id: string, dto: UpdateUserDto) {
if (id === '12345678-1234-1234-1234-123456789012') {
throw new BadRequestException('امکان ویرایش حساب ادمین پیش‌فرض وجود ندارد');
throw new BadRequestException(
'امکان ویرایش حساب ادمین پیش‌فرض وجود ندارد',
);
}
const user = await this.prisma.user.findUnique({ where: { id } });
@@ -208,31 +227,41 @@ export class AdminService {
throw new NotFoundException(`کاربری با شناسه ${id} یافت نشد`);
}
const normalizedMobile = dto.mobile ? normalizeMobile(dto.mobile) : undefined;
const normalizedMobile = dto.mobile
? normalizeMobile(dto.mobile)
: undefined;
if (normalizedMobile && normalizedMobile !== user.mobile) {
const existingMobile = await this.prisma.user.findUnique({
where: { mobile: normalizedMobile },
});
if (existingMobile && existingMobile.id !== id) {
throw new BadRequestException('این شماره موبایل متعلق به کاربر دیگری است');
throw new BadRequestException(
'این شماره موبایل متعلق به کاربر دیگری است',
);
}
}
const normalizedEmail = dto.email ? dto.email.trim().toLowerCase() : undefined;
const normalizedEmail = dto.email
? dto.email.trim().toLowerCase()
: undefined;
if (normalizedEmail && normalizedEmail !== user.email) {
const existingEmail = await this.prisma.user.findUnique({
where: { email: normalizedEmail },
});
if (existingEmail && existingEmail.id !== id) {
throw new BadRequestException('این آدرس ایمیل متعلق به کاربر دیگری است');
throw new BadRequestException(
'این آدرس ایمیل متعلق به کاربر دیگری است',
);
}
}
const updateData: Prisma.UserUpdateInput = {};
if (dto.firstName !== undefined) updateData.firstName = dto.firstName.trim();
if (dto.firstName !== undefined)
updateData.firstName = dto.firstName.trim();
if (dto.lastName !== undefined) updateData.lastName = dto.lastName.trim();
if (normalizedMobile !== undefined) updateData.mobile = normalizedMobile;
if (normalizedEmail !== undefined) updateData.email = normalizedEmail || null;
if (normalizedEmail !== undefined)
updateData.email = normalizedEmail || null;
if (dto.role !== undefined) updateData.role = dto.role;
if (dto.walletBalance !== undefined) {
updateData.walletBalance = new Prisma.Decimal(dto.walletBalance);
@@ -319,16 +348,28 @@ export class AdminService {
}
if (query.suitableFor && query.suitableFor !== 'all') {
andConditions.push({ suitableFor: { in: [query.suitableFor, 'سگ و گربه', 'هر دو'] } });
andConditions.push({
suitableFor: { in: [query.suitableFor, 'سگ و گربه', 'هر دو'] },
});
}
if (andConditions.length > 0) {
where.AND = andConditions;
}
const sortField = (query.sortBy && typeof query.sortBy === 'string' && ['nameFa', 'artNo', 'priceValue', 'packageSize', 'createdAt', 'updatedAt'].includes(query.sortBy))
? query.sortBy
: 'createdAt';
const sortField =
query.sortBy &&
typeof query.sortBy === 'string' &&
[
'nameFa',
'artNo',
'priceValue',
'packageSize',
'createdAt',
'updatedAt',
].includes(query.sortBy)
? query.sortBy
: 'createdAt';
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
const [data, total] = await Promise.all([
@@ -366,7 +407,8 @@ export class AdminService {
categorySlug: data.categorySlug || 'general',
buyPrice: data.buyPrice !== undefined ? data.buyPrice : 0,
priceValue: data.priceValue || 0,
wholesalePrice: data.wholesalePrice !== undefined ? data.wholesalePrice : null,
wholesalePrice:
data.wholesalePrice !== undefined ? data.wholesalePrice : null,
priceDisplay: data.priceDisplay || '',
unit: data.unit || 'عدد',
packageSize: data.packageSize || 100,
@@ -431,7 +473,8 @@ export class AdminService {
categorySlug: data.categorySlug,
buyPrice: data.buyPrice !== undefined ? data.buyPrice : undefined,
priceValue: data.priceValue,
wholesalePrice: data.wholesalePrice !== undefined ? data.wholesalePrice : undefined,
wholesalePrice:
data.wholesalePrice !== undefined ? data.wholesalePrice : undefined,
priceDisplay: data.priceDisplay,
unit: data.unit,
packageSize: data.packageSize,
@@ -444,16 +487,25 @@ export class AdminService {
? [data.images]
: undefined,
podcastUrl: data.podcastUrl !== undefined ? data.podcastUrl : undefined,
podcastTitle: data.podcastTitle !== undefined ? data.podcastTitle : undefined,
podcastDescription: data.podcastDescription !== undefined ? data.podcastDescription : undefined,
podcastCover: data.podcastCover !== undefined ? data.podcastCover : undefined,
podcastTitle:
data.podcastTitle !== undefined ? data.podcastTitle : undefined,
podcastDescription:
data.podcastDescription !== undefined
? data.podcastDescription
: undefined,
podcastCover:
data.podcastCover !== undefined ? data.podcastCover : undefined,
videoUrl: data.videoUrl !== undefined ? data.videoUrl : undefined,
videoTitle: data.videoTitle !== undefined ? data.videoTitle : undefined,
videoDescription: data.videoDescription !== undefined ? data.videoDescription : undefined,
videoDescription:
data.videoDescription !== undefined
? data.videoDescription
: undefined,
videoCover: data.videoCover !== undefined ? data.videoCover : undefined,
pdfUrl: data.pdfUrl !== undefined ? data.pdfUrl : undefined,
pdfTitle: data.pdfTitle !== undefined ? data.pdfTitle : undefined,
pdfDescription: data.pdfDescription !== undefined ? data.pdfDescription : undefined,
pdfDescription:
data.pdfDescription !== undefined ? data.pdfDescription : undefined,
pdfCover: data.pdfCover !== undefined ? data.pdfCover : undefined,
metaTitle: data.metaTitle,
metaDescription: data.metaDescription,
@@ -506,9 +558,14 @@ export class AdminService {
where.status = query.status;
}
const sortField = (query.sortBy && typeof query.sortBy === 'string' && ['createdAt', 'totalAmount', 'status', 'finalAmount'].includes(query.sortBy))
? query.sortBy
: 'createdAt';
const sortField =
query.sortBy &&
typeof query.sortBy === 'string' &&
['createdAt', 'totalAmount', 'status', 'finalAmount'].includes(
query.sortBy,
)
? query.sortBy
: 'createdAt';
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
const [data, total] = await Promise.all([
+20 -4
View File
@@ -1,4 +1,11 @@
import { IsNotEmpty, IsString, IsOptional, IsEmail, MinLength, IsNumber } from 'class-validator';
import {
IsNotEmpty,
IsString,
IsOptional,
IsEmail,
MinLength,
IsNumber,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class CreateUserDto {
@@ -17,7 +24,10 @@ export class CreateUserDto {
@IsString()
mobile!: string;
@ApiPropertyOptional({ description: 'ایمیل کاربر', example: 'ali@example.com' })
@ApiPropertyOptional({
description: 'ایمیل کاربر',
example: 'ali@example.com',
})
@IsOptional()
@IsEmail({}, { message: 'فرمت ایمیل نامعتبر است' })
email?: string;
@@ -55,12 +65,18 @@ export class UpdateUserDto {
@IsString()
mobile?: string;
@ApiPropertyOptional({ description: 'ایمیل کاربر', example: 'ali@example.com' })
@ApiPropertyOptional({
description: 'ایمیل کاربر',
example: 'ali@example.com',
})
@IsOptional()
@IsEmail({}, { message: 'فرمت ایمیل نامعتبر است' })
email?: string;
@ApiPropertyOptional({ description: 'رمز عبور جدید', example: 'NewPassword123' })
@ApiPropertyOptional({
description: 'رمز عبور جدید',
example: 'NewPassword123',
})
@IsOptional()
@IsString()
@MinLength(6, { message: 'رمز عبور باید حداقل ۶ کاراکتر باشد' })
+6 -2
View File
@@ -42,7 +42,9 @@ export class SslController {
@Post('upload')
@UseInterceptors(AnyFilesInterceptor())
@ApiOperation({ summary: 'آپلود فایل‌های گواهی SSL (FullChain/CRT و PrivateKey)' })
@ApiOperation({
summary: 'آپلود فایل‌های گواهی SSL (FullChain/CRT و PrivateKey)',
})
uploadFiles(
@UploadedFiles() files: Array<Express.Multer.File>,
@Body('certificateText') certText?: string,
@@ -90,7 +92,9 @@ export class SslController {
}
@Get('test-domain')
@ApiOperation({ summary: 'بررسی آنلاین گواهی SSL یک دامنه مشخص روی پورت ۴۴۳' })
@ApiOperation({
summary: 'بررسی آنلاین گواهی SSL یک دامنه مشخص روی پورت ۴۴۳',
})
testDomain(@Query('domain') domain: string) {
if (!domain) {
throw new BadRequestException('نام دامنه الزامی است');
+27 -10
View File
@@ -2,6 +2,7 @@ import { Injectable, Logger, BadRequestException } from '@nestjs/common';
import * as fs from 'fs';
import * as path from 'path';
import * as crypto from 'crypto';
import * as tls from 'tls';
export interface SslCertInfo {
exists: boolean;
@@ -21,14 +22,17 @@ export interface SslCertInfo {
@Injectable()
export class SslService {
private readonly logger = new Logger(SslService.name);
private readonly certsDir = process.env.SSL_CERTS_DIR || path.join(process.cwd(), 'ssl_certs');
private readonly certsDir =
process.env.SSL_CERTS_DIR || path.join(process.cwd(), 'ssl_certs');
constructor() {
if (!fs.existsSync(this.certsDir)) {
try {
fs.mkdirSync(this.certsDir, { recursive: true });
} catch (err) {
this.logger.warn(`Could not create ssl_certs dir at ${this.certsDir}: ${err}`);
this.logger.warn(
`Could not create ssl_certs dir at ${this.certsDir}: ${err}`,
);
}
}
}
@@ -69,7 +73,10 @@ export class SslService {
const validToDate = new Date(cert.validTo);
const now = new Date();
const diffMs = validToDate.getTime() - now.getTime();
const daysRemaining = Math.max(0, Math.floor(diffMs / (1000 * 60 * 60 * 24)));
const daysRemaining = Math.max(
0,
Math.floor(diffMs / (1000 * 60 * 60 * 24)),
);
const isExpired = diffMs <= 0;
// Extract SAN domains
@@ -108,7 +115,9 @@ export class SslService {
const cleanKey = keyContent.trim();
if (!cleanCert || !cleanKey) {
throw new BadRequestException('محتوای گواهی (Certificate) و کلید خصوصی (Private Key) الزامی است.');
throw new BadRequestException(
'محتوای گواهی (Certificate) و کلید خصوصی (Private Key) الزامی است.',
);
}
// 1. Validate Certificate format
@@ -117,7 +126,9 @@ export class SslService {
cert = new crypto.X509Certificate(cleanCert);
} catch (err: unknown) {
const errObj = err as Error;
throw new BadRequestException(`فرمت گواهی نامعتبر است: ${errObj.message}`);
throw new BadRequestException(
`فرمت گواهی نامعتبر است: ${errObj.message}`,
);
}
// 2. Validate Private Key format
@@ -125,7 +136,9 @@ export class SslService {
crypto.createPrivateKey(cleanKey);
} catch (err: unknown) {
const errObj = err as Error;
throw new BadRequestException(`فرمت کلید خصوصی نامعتبر است: ${errObj.message}`);
throw new BadRequestException(
`فرمت کلید خصوصی نامعتبر است: ${errObj.message}`,
);
}
// 3. Ensure certs directory exists
@@ -150,7 +163,9 @@ export class SslService {
fs.writeFileSync(certPath, cleanCert, 'utf8');
fs.writeFileSync(keyPath, cleanKey, 'utf8');
this.logger.log(`SSL Certificates updated successfully. Subject: ${cert.subject}`);
this.logger.log(
`SSL Certificates updated successfully. Subject: ${cert.subject}`,
);
return {
success: true,
@@ -161,8 +176,10 @@ export class SslService {
public testOnlineDomainSsl(domain: string): Promise<Record<string, unknown>> {
return new Promise((resolve) => {
const cleanDomain = domain.replace(/^https?:\/\//, '').replace(/\/.*$/, '').trim();
const tls = require('tls');
const cleanDomain = domain
.replace(/^https?:\/\//, '')
.replace(/\/.*$/, '')
.trim();
const socket = tls.connect(
{
host: cleanDomain,
@@ -192,7 +209,7 @@ export class SslService {
issuer: peerCert.issuer?.O || peerCert.issuer?.CN,
subject: peerCert.subject?.CN,
});
}
},
);
socket.on('error', (err: Error) => {