style: apply standard ESLint & Prettier formatting across backend
Deploy Canina / deploy (push) Successful in 4m58s
Deploy Canina / deploy (push) Successful in 4m58s
This commit is contained in:
1 parent
ae636c8b03
commit
62bd8811fa
66 files changed
+1398
-607
No files matched your search
@@ -8,26 +8,41 @@ export enum SortOrder {
|
||||
}
|
||||
|
||||
export class PaginationDto {
|
||||
@ApiPropertyOptional({ description: 'شماره صفحه (شروع از ۱)', minimum: 1, default: 1 })
|
||||
@ApiPropertyOptional({
|
||||
description: 'شماره صفحه (شروع از ۱)',
|
||||
minimum: 1,
|
||||
default: 1,
|
||||
})
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
page?: number = 1;
|
||||
|
||||
@ApiPropertyOptional({ description: 'تعداد آیتمها در هر صفحه', minimum: 1, default: 10 })
|
||||
@ApiPropertyOptional({
|
||||
description: 'تعداد آیتمها در هر صفحه',
|
||||
minimum: 1,
|
||||
default: 10,
|
||||
})
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
limit?: number = 10;
|
||||
|
||||
@ApiPropertyOptional({ description: 'فیلد برای مرتبسازی', default: 'createdAt' })
|
||||
@ApiPropertyOptional({
|
||||
description: 'فیلد برای مرتبسازی',
|
||||
default: 'createdAt',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
sortBy?: string = 'createdAt';
|
||||
|
||||
@ApiPropertyOptional({ description: 'جهت مرتبسازی (asc/desc)', enum: SortOrder, default: SortOrder.DESC })
|
||||
@ApiPropertyOptional({
|
||||
description: 'جهت مرتبسازی (asc/desc)',
|
||||
enum: SortOrder,
|
||||
default: SortOrder.DESC,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(SortOrder)
|
||||
sortOrder?: SortOrder = SortOrder.DESC;
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
|
||||
import {
|
||||
ExceptionFilter,
|
||||
Catch,
|
||||
ArgumentsHost,
|
||||
HttpException,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
|
||||
@Catch(HttpException)
|
||||
@@ -9,9 +14,17 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
const status = exception.getStatus();
|
||||
const exceptionResponse: any = exception.getResponse();
|
||||
|
||||
let message = typeof exceptionResponse === 'string' ? exceptionResponse : (exceptionResponse.message || 'خطای سرور');
|
||||
let code = typeof exceptionResponse === 'object' && exceptionResponse.error ? exceptionResponse.error : (status === 400 ? 'BAD_REQUEST' : 'ERROR');
|
||||
|
||||
let message =
|
||||
typeof exceptionResponse === 'string'
|
||||
? exceptionResponse
|
||||
: exceptionResponse.message || 'خطای سرور';
|
||||
let code =
|
||||
typeof exceptionResponse === 'object' && exceptionResponse.error
|
||||
? exceptionResponse.error
|
||||
: status === 400
|
||||
? 'BAD_REQUEST'
|
||||
: 'ERROR';
|
||||
|
||||
// Convert array of class-validator errors to a generic Farsi message if it's a 400
|
||||
if (Array.isArray(message) && status === 400) {
|
||||
message = 'اطلاعات وارد شده نامعتبر است. لطفاً فرم را بررسی کنید.';
|
||||
@@ -30,7 +43,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
success: false,
|
||||
message,
|
||||
code,
|
||||
details: typeof exceptionResponse === 'object' ? exceptionResponse : {}
|
||||
details: typeof exceptionResponse === 'object' ? exceptionResponse : {},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export class MetricsController {
|
||||
async getMetrics(@Res() res: express.Response) {
|
||||
const memory = process.memoryUsage();
|
||||
const cpu = process.cpuUsage();
|
||||
|
||||
|
||||
let dbStatus = 1;
|
||||
try {
|
||||
await this.prisma.$queryRaw`SELECT 1`;
|
||||
|
||||
@@ -4,12 +4,19 @@ export class ApiErrorResponse {
|
||||
@ApiProperty({ description: 'موفقیتآمیز بودن درخواست', example: false })
|
||||
success: boolean;
|
||||
|
||||
@ApiProperty({ description: 'پیام خطا', example: 'اطلاعات وارد شده نامعتبر است. لطفاً فرم را بررسی کنید.' })
|
||||
@ApiProperty({
|
||||
description: 'پیام خطا',
|
||||
example: 'اطلاعات وارد شده نامعتبر است. لطفاً فرم را بررسی کنید.',
|
||||
})
|
||||
message: string;
|
||||
|
||||
@ApiProperty({ description: 'کد خطا', example: 'BAD_REQUEST' })
|
||||
code: string;
|
||||
|
||||
@ApiProperty({ description: 'جزئیات خطا (در صورت وجود)', required: false, example: {} })
|
||||
@ApiProperty({
|
||||
description: 'جزئیات خطا (در صورت وجود)',
|
||||
required: false,
|
||||
example: {},
|
||||
})
|
||||
details?: any;
|
||||
}
|
||||
Reference in new issue
Block a user