chore(clean): pass all lint, typecheck and build checks with zero errors
This commit is contained in:
1 parent
6fa1f2c906
commit
a7d842ba10
19 files changed
+5185
-5110
No files matched your search
@@ -179,10 +179,11 @@ export class AdminService {
|
||||
]);
|
||||
|
||||
const enrichedUsers = data.map((u) => {
|
||||
const totalSpent = u.orders?.reduce(
|
||||
(acc, curr) => acc + (Number(curr.totalAmount) || 0),
|
||||
0,
|
||||
) || 0;
|
||||
const totalSpent =
|
||||
u.orders?.reduce(
|
||||
(acc, curr) => acc + (Number(curr.totalAmount) || 0),
|
||||
0,
|
||||
) || 0;
|
||||
const { orders, ...rest } = u;
|
||||
return {
|
||||
...rest,
|
||||
@@ -1194,8 +1195,7 @@ export class AdminService {
|
||||
dto.roundingStep !== undefined
|
||||
? Number(dto.roundingStep)
|
||||
: pricingSettings.roundingStep;
|
||||
const globalRoundingMode = (dto.roundingMode ||
|
||||
pricingSettings.roundingMode) as RoundingMode;
|
||||
const globalRoundingMode = dto.roundingMode || pricingSettings.roundingMode;
|
||||
const retailMargin = Number(dto.retailMarginPercent);
|
||||
const wholesaleMargin = Number(dto.wholesaleMarginPercent);
|
||||
|
||||
@@ -1285,7 +1285,8 @@ export class AdminService {
|
||||
roundingStep: updatedPricing.roundingStep,
|
||||
roundingMode: updatedPricing.roundingMode,
|
||||
defaultRetailMarginPercent: updatedPricing.defaultRetailMarginPercent,
|
||||
defaultWholesaleMarginPercent: updatedPricing.defaultWholesaleMarginPercent,
|
||||
defaultWholesaleMarginPercent:
|
||||
updatedPricing.defaultWholesaleMarginPercent,
|
||||
};
|
||||
await this.prisma.setting.upsert({
|
||||
where: { key: 'pricing_config' },
|
||||
@@ -1313,8 +1314,7 @@ export class AdminService {
|
||||
dto.roundingStep !== undefined
|
||||
? Number(dto.roundingStep)
|
||||
: pricingSettings.roundingStep;
|
||||
const roundingMode = (dto.roundingMode ||
|
||||
pricingSettings.roundingMode) as RoundingMode;
|
||||
const roundingMode = dto.roundingMode || pricingSettings.roundingMode;
|
||||
const applyRound = dto.applyRounding !== false;
|
||||
const adjValue = Number(dto.value || 0);
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ export class UpdatePricingSettingsDto {
|
||||
defaultWholesaleMarginPercent!: number;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'آیا قیمت تمام محصولات بر اساس فرمول جدید بلافاصله بهروزرسانی شود؟',
|
||||
description:
|
||||
'آیا قیمت تمام محصولات بر اساس فرمول جدید بلافاصله بهروزرسانی شود؟',
|
||||
default: true,
|
||||
})
|
||||
@IsOptional()
|
||||
@@ -44,12 +45,18 @@ export class UpdatePricingSettingsDto {
|
||||
}
|
||||
|
||||
export class ApplyGlobalMarginsDto {
|
||||
@ApiProperty({ description: 'درصد سود تکفروشی برای اعمال سراسری', example: 30 })
|
||||
@ApiProperty({
|
||||
description: 'درصد سود تکفروشی برای اعمال سراسری',
|
||||
example: 30,
|
||||
})
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
retailMarginPercent!: number;
|
||||
|
||||
@ApiProperty({ description: 'درصد سود عمدهفروشی برای اعمال سراسری', example: 15 })
|
||||
@ApiProperty({
|
||||
description: 'درصد سود عمدهفروشی برای اعمال سراسری',
|
||||
example: 15,
|
||||
})
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
wholesaleMarginPercent!: number;
|
||||
@@ -79,12 +86,16 @@ export class ApplyGlobalMarginsDto {
|
||||
@IsIn(['ALL', 'CATEGORY', 'SPECIFIC'])
|
||||
scope?: 'ALL' | 'CATEGORY' | 'SPECIFIC';
|
||||
|
||||
@ApiPropertyOptional({ description: 'شناسه دستهبندیها در صورت انتخاب دامنه CATEGORY' })
|
||||
@ApiPropertyOptional({
|
||||
description: 'شناسه دستهبندیها در صورت انتخاب دامنه CATEGORY',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
categoryIds?: string[];
|
||||
|
||||
@ApiPropertyOptional({ description: 'شناسه محصولات در صورت انتخاب دامنه SPECIFIC' })
|
||||
@ApiPropertyOptional({
|
||||
description: 'شناسه محصولات در صورت انتخاب دامنه SPECIFIC',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
productIds?: string[];
|
||||
@@ -100,12 +111,16 @@ export class BulkPriceAdjustmentDto {
|
||||
@IsIn(['ALL', 'CATEGORY', 'SPECIFIC'])
|
||||
scope!: 'ALL' | 'CATEGORY' | 'SPECIFIC';
|
||||
|
||||
@ApiPropertyOptional({ description: 'شناسه دستهبندیها در صورت انتخاب دامنه CATEGORY' })
|
||||
@ApiPropertyOptional({
|
||||
description: 'شناسه دستهبندیها در صورت انتخاب دامنه CATEGORY',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
categoryIds?: string[];
|
||||
|
||||
@ApiPropertyOptional({ description: 'شناسه محصولات در صورت انتخاب دامنه SPECIFIC' })
|
||||
@ApiPropertyOptional({
|
||||
description: 'شناسه محصولات در صورت انتخاب دامنه SPECIFIC',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
productIds?: string[];
|
||||
@@ -129,7 +144,8 @@ export class BulkPriceAdjustmentDto {
|
||||
adjustmentType!: 'PERCENT' | 'FIXED';
|
||||
|
||||
@ApiProperty({
|
||||
description: 'جهت تغییر: INCREASE (افزایش / گرانتر) یا DECREASE (کاهش / ارزانتر)',
|
||||
description:
|
||||
'جهت تغییر: INCREASE (افزایش / گرانتر) یا DECREASE (کاهش / ارزانتر)',
|
||||
enum: ['INCREASE', 'DECREASE'],
|
||||
example: 'INCREASE',
|
||||
})
|
||||
@@ -138,19 +154,26 @@ export class BulkPriceAdjustmentDto {
|
||||
adjustmentDirection!: 'INCREASE' | 'DECREASE';
|
||||
|
||||
@ApiProperty({
|
||||
description: 'مقدار تغییر (مثلاً 10 برای 10 درصد، یا 100000 برای 100 هزار تومان)',
|
||||
description:
|
||||
'مقدار تغییر (مثلاً 10 برای 10 درصد، یا 100000 برای 100 هزار تومان)',
|
||||
example: 10,
|
||||
})
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
value!: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'آیا پس از تغییر قیمت، گرد کردن اعمال شود؟', default: true })
|
||||
@ApiPropertyOptional({
|
||||
description: 'آیا پس از تغییر قیمت، گرد کردن اعمال شود؟',
|
||||
default: true,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
applyRounding?: boolean;
|
||||
|
||||
@ApiPropertyOptional({ description: 'گام گرد کردن سفارشی (در صورت خالی بودن از تنظیمات سیستم استفاده میشود)' })
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'گام گرد کردن سفارشی (در صورت خالی بودن از تنظیمات سیستم استفاده میشود)',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
roundingStep?: number;
|
||||
|
||||
@@ -83,7 +83,9 @@ export class ProductDto {
|
||||
@IsNumber()
|
||||
wholesaleMarginPercent?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'گام گرد کردن اختصاصی این محصول (اختیاری)' })
|
||||
@ApiPropertyOptional({
|
||||
description: 'گام گرد کردن اختصاصی این محصول (اختیاری)',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
roundingStep?: number;
|
||||
|
||||
@@ -82,7 +82,13 @@ export class BlogsController {
|
||||
@ApiOperation({ summary: 'ارسال نظر برای مقاله' })
|
||||
addComment(
|
||||
@Param('slug') slug: string,
|
||||
@Body() body: { userName: string; email?: string; content: string; userId?: string },
|
||||
@Body()
|
||||
body: {
|
||||
userName: string;
|
||||
email?: string;
|
||||
content: string;
|
||||
userId?: string;
|
||||
},
|
||||
) {
|
||||
return this.blogsService.addComment(slug, body);
|
||||
}
|
||||
|
||||
@@ -357,7 +357,12 @@ export class BlogsService {
|
||||
|
||||
async addComment(
|
||||
slug: string,
|
||||
data: { userName: string; email?: string; content: string; userId?: string },
|
||||
data: {
|
||||
userName: string;
|
||||
email?: string;
|
||||
content: string;
|
||||
userId?: string;
|
||||
},
|
||||
) {
|
||||
const blog = await this.prisma.blog.findUnique({
|
||||
where: { slug },
|
||||
|
||||
@@ -111,10 +111,11 @@ export class ProductsService {
|
||||
const isAdmin = userRole === 'ADMIN' || userRole === 'SuperAdmin';
|
||||
|
||||
const data = rawProducts.map((p) => {
|
||||
const totalSold = p.orderItems?.reduce(
|
||||
(acc, item) => acc + (Number(item.quantity) || 0),
|
||||
0,
|
||||
) || 0;
|
||||
const totalSold =
|
||||
p.orderItems?.reduce(
|
||||
(acc, item) => acc + (Number(item.quantity) || 0),
|
||||
0,
|
||||
) || 0;
|
||||
const { buyPrice, wholesalePrice, orderItems, ...publicProduct } = p;
|
||||
void buyPrice;
|
||||
void wholesalePrice;
|
||||
|
||||
@@ -69,13 +69,14 @@ function buildTorobProductSpec(product: {
|
||||
category?: { name?: string } | null;
|
||||
}): Record<string, string> {
|
||||
const spec: Record<string, string> = {
|
||||
'برند': 'کنینا (Canina Pharma Germany)',
|
||||
برند: 'کنینا (Canina Pharma Germany)',
|
||||
'کشور سازنده': 'آلمان',
|
||||
'ضمانت': 'اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی',
|
||||
ضمانت: 'اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی',
|
||||
};
|
||||
|
||||
if (product.suitableFor) {
|
||||
spec['گونه هدف'] = product.suitableFor === 'هر دو' ? 'سگ و گربه' : product.suitableFor;
|
||||
spec['گونه هدف'] =
|
||||
product.suitableFor === 'هر دو' ? 'سگ و گربه' : product.suitableFor;
|
||||
}
|
||||
|
||||
const numSize = Number(product.packageSize);
|
||||
@@ -101,14 +102,22 @@ export class TorobController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get('products')
|
||||
@ApiOperation({ summary: 'دریافت محصولات جهت وبسرویس خودکار ترب (Torob API)' })
|
||||
@ApiOperation({
|
||||
summary: 'دریافت محصولات جهت وبسرویس خودکار ترب (Torob API)',
|
||||
})
|
||||
async getTorobProducts(
|
||||
@Query('page') pageQuery?: string,
|
||||
@Query('page_size') pageSizeQuery?: string,
|
||||
) {
|
||||
const page = Math.max(1, parseInt(pageQuery || '1', 10));
|
||||
const pageSize = Math.min(100, Math.max(10, parseInt(pageSizeQuery || '100', 10)));
|
||||
const baseUrl = (process.env.FRONTEND_URL || 'https://canina.ir').replace(/\/$/, '');
|
||||
const pageSize = Math.min(
|
||||
100,
|
||||
Math.max(10, parseInt(pageSizeQuery || '100', 10)),
|
||||
);
|
||||
const baseUrl = (process.env.FRONTEND_URL || 'https://canina.ir').replace(
|
||||
/\/$/,
|
||||
'',
|
||||
);
|
||||
|
||||
const whereCondition = {
|
||||
noIndex: false,
|
||||
@@ -134,7 +143,7 @@ export class TorobController {
|
||||
const slug = product.slug || product.artNo || product.id;
|
||||
const pageUrl = `${baseUrl}/shop/${slug}`;
|
||||
const productId = String(product.artNo || product.id || slug);
|
||||
|
||||
|
||||
const title = buildTorobProductTitle(product);
|
||||
const spec = buildTorobProductSpec(product);
|
||||
|
||||
@@ -142,8 +151,15 @@ export class TorobController {
|
||||
const rawEn = (product.nameEn || '').trim();
|
||||
const numSize = Number(product.packageSize);
|
||||
const unit = (product.unit || '').trim();
|
||||
const sizeStr = numSize && numSize > 0 ? (unit ? `${numSize} ${unit}` : `${numSize}`) : '';
|
||||
let subtitle = rawEn.startsWith('Canina') ? rawEn : `Canina ${rawEn}`.trim();
|
||||
const sizeStr =
|
||||
numSize && numSize > 0
|
||||
? unit
|
||||
? `${numSize} ${unit}`
|
||||
: `${numSize}`
|
||||
: '';
|
||||
let subtitle = rawEn.startsWith('Canina')
|
||||
? rawEn
|
||||
: `Canina ${rawEn}`.trim();
|
||||
if (sizeStr && !subtitle.includes(sizeStr)) {
|
||||
subtitle = `${subtitle} - ${sizeStr}`;
|
||||
}
|
||||
@@ -151,12 +167,16 @@ export class TorobController {
|
||||
const rawImage = product.ogImage || product.imageUrl || '';
|
||||
let imageLink = '';
|
||||
if (rawImage) {
|
||||
const cleanImage = rawImage.trim()
|
||||
const cleanImage = rawImage
|
||||
.trim()
|
||||
.replace(/^https?:\/\/api\.canina\.ir/i, '')
|
||||
.replace(/^https?:\/\/localhost:\d+/i, '')
|
||||
.replace(/^https?:\/\/127\.0\.0\.1:\d+/i, '');
|
||||
|
||||
if (cleanImage.startsWith('http://') || cleanImage.startsWith('https://')) {
|
||||
if (
|
||||
cleanImage.startsWith('http://') ||
|
||||
cleanImage.startsWith('https://')
|
||||
) {
|
||||
imageLink = cleanImage;
|
||||
} else {
|
||||
const cleanPath = cleanImage.replace(/^\/?(api\/)?(uploads\/)?/, '');
|
||||
@@ -164,7 +184,11 @@ export class TorobController {
|
||||
}
|
||||
}
|
||||
|
||||
const isInStock = product.stockStatus !== 'DISCONTINUED' && String(product.stockStatus || '').toLowerCase().includes('in');
|
||||
const isInStock =
|
||||
product.stockStatus !== 'DISCONTINUED' &&
|
||||
String(product.stockStatus || '')
|
||||
.toLowerCase()
|
||||
.includes('in');
|
||||
const price = Number(product.priceValue || 0);
|
||||
const oldPrice = Number(product.priceValue || 0);
|
||||
|
||||
@@ -179,7 +203,10 @@ export class TorobController {
|
||||
availability: isInStock ? 'instock' : 'outofstock',
|
||||
image_link: imageLink,
|
||||
guarantee: 'ضمانت اصالت ۱۰۰٪ کمپانی Canina آلمان و اصالت کالا',
|
||||
category_name: product.category?.name || product.categorySlug || 'مکمل حیوانات خانگی',
|
||||
category_name:
|
||||
product.category?.name ||
|
||||
product.categorySlug ||
|
||||
'مکمل حیوانات خانگی',
|
||||
spec,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -36,7 +36,8 @@ export class VideosService {
|
||||
}
|
||||
|
||||
const sortField =
|
||||
query.sortBy && ['createdAt', 'viewsCount', 'title', 'isFeatured'].includes(query.sortBy)
|
||||
query.sortBy &&
|
||||
['createdAt', 'viewsCount', 'title', 'isFeatured'].includes(query.sortBy)
|
||||
? query.sortBy
|
||||
: 'createdAt';
|
||||
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
Reference in new issue
Block a user