fix : put attibute value directl in product

This commit is contained in:
morteza-mortezai
2025-10-25 16:35:48 +03:30
parent 6f19c6c384
commit 0c589165c2
2 changed files with 25 additions and 23 deletions
+3 -2
View File
@@ -115,8 +115,9 @@ export class Attributes {
@Expose()
@IsNotEmpty()
@IsArray()
values: number[];
values: (string | number)[];
}
export class ProductStepTwoDTO {
@Expose()
@IsNotEmpty()
@@ -127,7 +128,7 @@ export class ProductStepTwoDTO {
@Expose()
@IsArray()
@ArrayMinSize(1)
@ArrayMinSize(0)
@ValidateNested({ each: true })
@Type(() => Attributes)
@ApiProperty({
@@ -161,17 +161,18 @@ class ProductService {
}
// Fetch the attribute values from the database
const attributeValues = await this.attributeValueRepo.model.find({
_id: { $in: attribute.values },
});
// const attributeValues = await this.attributeValueRepo.model.find({
// _id: { $in: attribute.values },
// });
// Check if any attribute values were found
if (attributeValues.length === 0) {
throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
}
// if (attributeValues.length === 0 ) {
// throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
// }
// Map the values to their text value
const selectedValues = attributeValues.map((val: IAttributeValue) => val.text);
// const selectedValues = attributeValues.map((val: IAttributeValue) => val.text);
const selectedValues = attribute.values.map((val) => String(val));
specifications.push({
title: attributeDetails.title,
@@ -279,17 +280,17 @@ class ProductService {
}
// Fetch the attribute values from the database
const attributeValues = await this.attributeValueRepo.model.find({
_id: { $in: attribute.values },
});
// const attributeValues = await this.attributeValueRepo.model.find({
// _id: { $in: attribute.values },
// });
// Check if any attribute values were found
if (attributeValues.length === 0) {
throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
}
// if (attributeValues.length === 0) {
// throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
// }
// Map the values to their text value
const selectedValues = attributeValues.map((val: IAttributeValue) => val.text);
const selectedValues = attribute.values.map((val) => String(val));
specifications.push({
title: attributeDetails.title,
@@ -423,15 +424,15 @@ class ProductService {
throw new BadRequestError(AttributeMessage.AttributeIdIsIncorrect);
}
const attributeValues = await this.attributeValueRepo.model.find({
_id: { $in: attribute.values },
});
// const attributeValues = await this.attributeValueRepo.model.find({
// _id: { $in: attribute.values },
// });
if (attributeValues.length === 0) {
throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
}
// if (attributeValues.length === 0) {
// throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
// }
const selectedValues = attributeValues.map((val: IAttributeValue) => val.text);
const selectedValues = attribute.values.map((val) => String(val));
specifications.push({
title: attributeDetails.title,