From 6ee18d4ae1d27494ab40460eed6e32c7bdf86abc Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Fri, 13 Feb 2026 19:12:10 +0330 Subject: [PATCH] delete variant --- src/modules/product/Repository/productVarinat.ts | 7 +++++++ .../product/models/Abstraction/IProductVariant.ts | 1 + src/modules/product/models/productVariant.model.ts | 1 + src/modules/product/product.controller.ts | 11 +++++++++++ src/modules/product/providers/product.service.ts | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/src/modules/product/Repository/productVarinat.ts b/src/modules/product/Repository/productVarinat.ts index 36b6425..78aa2fc 100644 --- a/src/modules/product/Repository/productVarinat.ts +++ b/src/modules/product/Repository/productVarinat.ts @@ -11,6 +11,10 @@ export class ProductVariantRepository extends BaseRepository { super(ProductVariantModel); } + override async findById(id: string | number) { + return this.model.findOne({ _id: id, deleted: false }); + } + async getProductVariants(shopId: string, productId: number, queries: VariantQueries) { const page = queries.page || 1; const limit = queries.limit || 10; @@ -19,6 +23,7 @@ export class ProductVariantRepository extends BaseRepository { const matchQuery: any = { shop: new Types.ObjectId(shopId), product: productId, + deleted: false, }; const sortBy: any = { @@ -182,6 +187,7 @@ export class ProductVariantRepository extends BaseRepository { const matchQuery: any = { shop: new Types.ObjectId(shopId), + deleted: false, }; const sortBy: any = { @@ -329,6 +335,7 @@ export class ProductVariantRepository extends BaseRepository { _id: new Types.ObjectId(variantId), shop: new Types.ObjectId(shopId), product: productId, + deleted: false, }, }, { diff --git a/src/modules/product/models/Abstraction/IProductVariant.ts b/src/modules/product/models/Abstraction/IProductVariant.ts index e2d8129..b63c4f2 100644 --- a/src/modules/product/models/Abstraction/IProductVariant.ts +++ b/src/modules/product/models/Abstraction/IProductVariant.ts @@ -22,6 +22,7 @@ export interface IProductVariant { dimensions: IDimensions; sellerSpecialCode: string; themeValue: Types.ObjectId; + deleted: boolean } export interface IPrice { diff --git a/src/modules/product/models/productVariant.model.ts b/src/modules/product/models/productVariant.model.ts index e1a1248..0795fe6 100644 --- a/src/modules/product/models/productVariant.model.ts +++ b/src/modules/product/models/productVariant.model.ts @@ -60,6 +60,7 @@ const productVariantSchema = new Schema( dimensions: { type: productDimensionsSchema, required: true }, sellerSpecialCode: { type: String }, themeValue: { type: Schema.Types.ObjectId, ref: "ThemeValue", required: true }, + deleted: { type: Boolean, default: false }, }, { timestamps: true, toObject: { virtuals: true, versionKey: false }, toJSON: { virtuals: true, versionKey: false }, id: false }, ); diff --git a/src/modules/product/product.controller.ts b/src/modules/product/product.controller.ts index 95bfaef..ed90729 100644 --- a/src/modules/product/product.controller.ts +++ b/src/modules/product/product.controller.ts @@ -306,6 +306,17 @@ class ProductController extends BaseController { return this.response(data); } + @ApiOperation("Delete product variant as admin ") + @ApiResponse("successfully", HttpStatus.Ok) + @ApiParam("id", "id of product variant", true) + @ApiParam("variantId", "id of product variant", true) + @ApiAuth() + @httpDelete("/variants/:variantId", Guard.authAdmin()) + public async removeVariant(@queryParam() paramDto: SetFreeShipParamDto) { + const data = await this.productService.softDeleteProductVariant( paramDto.variantId); + return this.response(data); + } + @ApiOperation("update a variant of product ==> need to login as seller") @ApiResponse("successfully", HttpStatus.Created) @ApiModel(UpdateVariantDTO) diff --git a/src/modules/product/providers/product.service.ts b/src/modules/product/providers/product.service.ts index 5089dc2..a70f3d3 100644 --- a/src/modules/product/providers/product.service.ts +++ b/src/modules/product/providers/product.service.ts @@ -1103,6 +1103,11 @@ class ProductService { } } + async softDeleteProductVariant(variantId: string) { + await this.productVariantRepo.model.findOneAndUpdate({ _id: variantId }, { deleted: true }); + return { message: 'Deleted successfully' } + } + //################################################################ async cloneProduct(ownerId: string, productId: number) { const product = await this.validateProduct(productId, ownerId);