delete variant

This commit is contained in:
2026-02-13 19:12:10 +03:30
parent afd263523d
commit 6ee18d4ae1
5 changed files with 25 additions and 0 deletions
@@ -11,6 +11,10 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
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<IProductVariant> {
const matchQuery: any = {
shop: new Types.ObjectId(shopId),
product: productId,
deleted: false,
};
const sortBy: any = {
@@ -182,6 +187,7 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
const matchQuery: any = {
shop: new Types.ObjectId(shopId),
deleted: false,
};
const sortBy: any = {
@@ -329,6 +335,7 @@ export class ProductVariantRepository extends BaseRepository<IProductVariant> {
_id: new Types.ObjectId(variantId),
shop: new Types.ObjectId(shopId),
product: productId,
deleted: false,
},
},
{
@@ -22,6 +22,7 @@ export interface IProductVariant {
dimensions: IDimensions;
sellerSpecialCode: string;
themeValue: Types.ObjectId;
deleted: boolean
}
export interface IPrice {
@@ -60,6 +60,7 @@ const productVariantSchema = new Schema<IProductVariant>(
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 },
);
+11
View File
@@ -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)
@@ -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);