fix(admin-products): add class-validator ProductDto to allow product creation and updates through ValidationPipe
Deploy Canina / deploy (push) Successful in 32s

This commit is contained in:
parsa aghaei committed 2026-08-18 10:34:52 +03:30
1 parent 4cbde63b89
commit d5c05b7577
3 files changed
+176 -33

No files matched your search

+7 -30
View File
@@ -9,6 +9,7 @@ import { PrismaService } from '../prisma/prisma.service';
import { RedisService } from '../redis/redis.service';
import * as bcrypt from 'bcryptjs';
import { CreateUserDto, UpdateUserDto } from './dto/user.dto';
import { ProductDto } from './dto/product.dto';
import { normalizeMobile } from '../common/utils/phone.utils';
import { CANONICAL_ALIASES } from '../settings/settings.service';
@@ -21,34 +22,6 @@ export class PaginationQuery {
status?: string;
}
export class ProductInput {
artNo?: string;
nameFa?: string;
nameEn?: string;
scientificTagline?: string;
description?: string;
shortDescription?: string;
categoryId?: string;
categorySlug?: string;
priceValue?: number;
priceDisplay?: string;
unit?: string;
packageSize?: number;
dosageLogic?: string;
suitableFor?: string;
imageUrl?: string;
images?: string | string[];
podcastUrl?: string | null;
videoUrl?: string | null;
pdfUrl?: string | null;
metaTitle?: string;
metaDescription?: string;
keywords?: string;
canonicalUrl?: string;
slug?: string;
symptoms?: string[];
}
export class CouponTargetInput {
targetType!: string;
targetId!: string;
@@ -333,7 +306,7 @@ export class AdminService {
}
}
async createProduct(data: ProductInput) {
async createProduct(data: ProductDto) {
const product = await this.prisma.product.create({
data: {
artNo: data.artNo || `ART-${Date.now()}`,
@@ -344,7 +317,9 @@ export class AdminService {
shortDescription: data.shortDescription || '',
categoryId: data.categoryId || '',
categorySlug: data.categorySlug || 'general',
buyPrice: data.buyPrice !== undefined ? data.buyPrice : 0,
priceValue: data.priceValue || 0,
wholesalePrice: data.wholesalePrice !== undefined ? data.wholesalePrice : null,
priceDisplay: data.priceDisplay || '',
unit: data.unit || 'عدد',
packageSize: data.packageSize || 100,
@@ -381,7 +356,7 @@ export class AdminService {
return product;
}
async updateProduct(id: string, data: ProductInput) {
async updateProduct(id: string, data: ProductDto) {
const existing = await this.prisma.product.findUnique({ where: { id } });
if (!existing) {
throw new NotFoundException(`محصولی با شناسه ${id} یافت نشد.`);
@@ -398,7 +373,9 @@ export class AdminService {
shortDescription: data.shortDescription,
categoryId: data.categoryId,
categorySlug: data.categorySlug,
buyPrice: data.buyPrice !== undefined ? data.buyPrice : undefined,
priceValue: data.priceValue,
wholesalePrice: data.wholesalePrice !== undefined ? data.wholesalePrice : undefined,
priceDisplay: data.priceDisplay,
unit: data.unit,
packageSize: data.packageSize,