fix : put attibute value directl in product
This commit is contained in:
@@ -115,8 +115,9 @@ export class Attributes {
|
|||||||
@Expose()
|
@Expose()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
values: number[];
|
values: (string | number)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ProductStepTwoDTO {
|
export class ProductStepTwoDTO {
|
||||||
@Expose()
|
@Expose()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -127,7 +128,7 @@ export class ProductStepTwoDTO {
|
|||||||
|
|
||||||
@Expose()
|
@Expose()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ArrayMinSize(1)
|
@ArrayMinSize(0)
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => Attributes)
|
@Type(() => Attributes)
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
|
|||||||
@@ -161,17 +161,18 @@ class ProductService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the attribute values from the database
|
// Fetch the attribute values from the database
|
||||||
const attributeValues = await this.attributeValueRepo.model.find({
|
// const attributeValues = await this.attributeValueRepo.model.find({
|
||||||
_id: { $in: attribute.values },
|
// _id: { $in: attribute.values },
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Check if any attribute values were found
|
// Check if any attribute values were found
|
||||||
if (attributeValues.length === 0) {
|
// if (attributeValues.length === 0 ) {
|
||||||
throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
|
// throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Map the values to their text value
|
// 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({
|
specifications.push({
|
||||||
title: attributeDetails.title,
|
title: attributeDetails.title,
|
||||||
@@ -279,17 +280,17 @@ class ProductService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the attribute values from the database
|
// Fetch the attribute values from the database
|
||||||
const attributeValues = await this.attributeValueRepo.model.find({
|
// const attributeValues = await this.attributeValueRepo.model.find({
|
||||||
_id: { $in: attribute.values },
|
// _id: { $in: attribute.values },
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Check if any attribute values were found
|
// Check if any attribute values were found
|
||||||
if (attributeValues.length === 0) {
|
// if (attributeValues.length === 0) {
|
||||||
throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
|
// throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Map the values to their text value
|
// 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({
|
specifications.push({
|
||||||
title: attributeDetails.title,
|
title: attributeDetails.title,
|
||||||
@@ -423,15 +424,15 @@ class ProductService {
|
|||||||
throw new BadRequestError(AttributeMessage.AttributeIdIsIncorrect);
|
throw new BadRequestError(AttributeMessage.AttributeIdIsIncorrect);
|
||||||
}
|
}
|
||||||
|
|
||||||
const attributeValues = await this.attributeValueRepo.model.find({
|
// const attributeValues = await this.attributeValueRepo.model.find({
|
||||||
_id: { $in: attribute.values },
|
// _id: { $in: attribute.values },
|
||||||
});
|
// });
|
||||||
|
|
||||||
if (attributeValues.length === 0) {
|
// if (attributeValues.length === 0) {
|
||||||
throw new BadRequestError(`No valid attribute values found for attribute id ${attribute.id}`);
|
// 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({
|
specifications.push({
|
||||||
title: attributeDetails.title,
|
title: attributeDetails.title,
|
||||||
|
|||||||
Reference in New Issue
Block a user