From e469a2eadd3e5a42825281e67c278a19da498bf2 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 26 Oct 2025 16:50:17 +0330 Subject: [PATCH 1/2] add: admin shop shipment --- .../admin/controllers/shipment.controller.ts | 27 ++++++++++++++++++- .../admin/controllers/shop.controller.ts | 12 ++++++++- src/modules/seller/seller.service.ts | 23 ++++++++++++++++ src/modules/shop/shop.repository.ts | 6 ++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/modules/admin/controllers/shipment.controller.ts b/src/modules/admin/controllers/shipment.controller.ts index 578f954..3b6c475 100644 --- a/src/modules/admin/controllers/shipment.controller.ts +++ b/src/modules/admin/controllers/shipment.controller.ts @@ -1,5 +1,6 @@ +import { Request } from "express"; import { inject } from "inversify"; -import { controller, httpDelete, httpGet, httpPatch, httpPost, requestBody, requestParam } from "inversify-express-utils"; +import { controller, httpDelete, httpGet, httpPatch, httpPost, request, requestBody, requestParam } from "inversify-express-utils"; import { HttpStatus } from "../../../common"; import { BaseController } from "../../../common/base/controller"; @@ -7,15 +8,19 @@ import { ApiAuth, ApiModel, ApiOperation, ApiParam, ApiResponse, ApiTags } from import { Guard } from "../../../core/middlewares/guard.middleware"; import { ValidationMiddleware } from "../../../core/middlewares/validator.middleware"; import { IOCTYPES } from "../../../IOC/ioc.types"; +import { UpdateShopShipmentDTO } from "../../seller/DTO/update-shop-shipment.dto"; +import { SellerService } from "../../seller/seller.service"; import { CreateShipProvidersDTO } from "../../shipment/DTO/createShipmentProviders.dto"; import { UpdateShipmentProviderDTO } from "../../shipment/DTO/updateShipment.dto"; import { ShipmentService } from "../../shipment/shipment.service"; +import { IAdmin } from "../models/Abstraction/IAdmin"; import { PermissionEnum } from "../models/Abstraction/IPermission"; @ApiTags("Admin Shipment") @controller("/admin/shipment") export class AdminShipmentController extends BaseController { @inject(IOCTYPES.ShipmentService) private shipmentService: ShipmentService; + @inject(IOCTYPES.SellerService) private sellerService: SellerService; //=================================================> //shipment @ApiOperation("create a shipment provider") @@ -58,4 +63,24 @@ export class AdminShipmentController extends BaseController { const data = await this.shipmentService.getShipperDetail(+shipperId); return this.response(data); } + + @ApiOperation("activate the admin shop shipment method") + @ApiModel(UpdateShopShipmentDTO) + @ApiAuth() + @httpPatch("/shipment/activate", Guard.authAdmin(), ValidationMiddleware.validateInput(UpdateShopShipmentDTO)) + public async activateShopShipper(@request() req: Request, @requestBody() updateDto: UpdateShopShipmentDTO) { + const admin = req.user as IAdmin; + const data = await this.sellerService.updateShopShipperForAdmin(admin._id.toString(), updateDto, "activate"); + return this.response(data); + } + + @ApiOperation("deactivate the admin shop shipment method") + @ApiModel(UpdateShopShipmentDTO) + @ApiAuth() + @httpPatch("/shipment/deactivate", Guard.authAdmin(), ValidationMiddleware.validateInput(UpdateShopShipmentDTO)) + public async deactivateShopShipper(@request() req: Request, @requestBody() updateDto: UpdateShopShipmentDTO) { + const admin = req.user as IAdmin; + const data = await this.sellerService.updateShopShipperForAdmin(admin._id.toString(), updateDto, "deactivate"); + return this.response(data); + } } diff --git a/src/modules/admin/controllers/shop.controller.ts b/src/modules/admin/controllers/shop.controller.ts index 354e763..f715d9d 100644 --- a/src/modules/admin/controllers/shop.controller.ts +++ b/src/modules/admin/controllers/shop.controller.ts @@ -1,6 +1,6 @@ import { Request } from "express"; import { inject } from "inversify"; -import { controller, httpPatch, httpPost, request, requestBody, requestParam } from "inversify-express-utils"; +import { controller, httpGet, httpPatch, httpPost, request, requestBody, requestParam } from "inversify-express-utils"; import { HttpStatus } from "../../../common"; import { BaseController } from "../../../common/base/controller"; @@ -10,6 +10,7 @@ import { ValidationMiddleware } from "../../../core/middlewares/validator.middle import { IOCTYPES } from "../../../IOC/ioc.types"; import { ProductFinalStepDTO, ProductStepOneDTO, ProductStepTwoDTO } from "../../product/DTO/CreateProduct.dto"; import { ProductService } from "../../product/providers/product.service"; +import { ShopRepo } from "../../shop/shop.repository"; import { AdminService } from "../admin.service"; import { IAdmin } from "../models/Abstraction/IAdmin"; @@ -18,6 +19,7 @@ import { IAdmin } from "../models/Abstraction/IAdmin"; export class AdminShopController extends BaseController { @inject(IOCTYPES.ProductService) private productService: ProductService; @inject(IOCTYPES.AdminService) private adminService: AdminService; + @inject(IOCTYPES.ShopRepo) private shopRepo: ShopRepo; //############################################################### //create product for shop @@ -69,5 +71,13 @@ export class AdminShopController extends BaseController { return this.response(data); } + @ApiOperation("get admin shop") + @ApiAuth() + @httpGet("/", Guard.authAdmin()) + public async getAdminShop() { + const data = await this.shopRepo.findAdminShop(); + return this.response({ data }, HttpStatus.Ok); + } + //############################################################### } diff --git a/src/modules/seller/seller.service.ts b/src/modules/seller/seller.service.ts index 6a28a12..c2acee1 100644 --- a/src/modules/seller/seller.service.ts +++ b/src/modules/seller/seller.service.ts @@ -327,6 +327,29 @@ class SellerService { }; } + async updateShopShipperForAdmin(sellerId: string, updateDto: UpdateShopShipmentDTO, type: "activate" | "deactivate") { + const { shipmentId } = updateDto; + + const shop = await this.shopRepo.model.findOne({ owner: sellerId, ownerRef: OwnerRef.ADMIN }); + if (!shop) throw new BadRequestError(ShopMessage.ShopNotFound); + + if (type === "activate") { + if (shop.shipmentMethod.includes(shipmentId)) throw new BadRequestError(SetShipmentMessage.ShipmentMethodAlreadyActive); + + shop.shipmentMethod.push(shipmentId); + } else { + if (!shop.shipmentMethod.includes(shipmentId)) throw new BadRequestError(SetShipmentMessage.ShipmentMethodNotActive); + + shop.shipmentMethod = shop.shipmentMethod.filter((methodId) => methodId !== shipmentId); + } + + await shop.save(); + + return { + message: CommonMessage.Updated, + }; + } + async changeShopChatStatus(sellerId: string) { const shop = await this.shopRepo.model.findOne({ owner: sellerId, ownerRef: OwnerRef.SELLER }); if (!shop) throw new BadRequestError(ShopMessage.ShopNotFound); diff --git a/src/modules/shop/shop.repository.ts b/src/modules/shop/shop.repository.ts index d8aa222..0f7238a 100644 --- a/src/modules/shop/shop.repository.ts +++ b/src/modules/shop/shop.repository.ts @@ -1,4 +1,4 @@ -import { IShop } from "./models/Abstraction/IShop"; +import { IShop, OwnerRef } from "./models/Abstraction/IShop"; import { ShopModel } from "./models/shop.model"; import { BaseRepository } from "../../common/base/repository"; @@ -10,6 +10,10 @@ export class ShopRepo extends BaseRepository { async findWithShopcode(shopCode: number) { return this.model.findOne({ shopCode }, { _id: 1, shopName: 1, shopCode: 1, shopDescription: 1, logo: 1 }); } + + async findAdminShop() { + return this.model.findOne({ ownerRef: OwnerRef.ADMIN }).populate({ path: "shipmentMethod" }); + } } export function createShopRepo(): ShopRepo { From 9af567c91a39c6ccb77f49590f8e1e84e2d6fa2e Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 26 Oct 2025 16:57:53 +0330 Subject: [PATCH 2/2] fix : min Product varient price decrased to 1000 --- src/modules/product/DTO/addVariant.dto.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/product/DTO/addVariant.dto.ts b/src/modules/product/DTO/addVariant.dto.ts index a94abbe..81f9d9d 100644 --- a/src/modules/product/DTO/addVariant.dto.ts +++ b/src/modules/product/DTO/addVariant.dto.ts @@ -58,7 +58,7 @@ export class AddVariantDTO { @Expose() @IsNotEmpty() - @Min(10000, { message: "حداقل قیمت برای کالا ۱۰۰۰۰ تومان می باشد " }) + @Min(1000, { message: "حداقل قیمت برای کالا ۱۰۰۰۰ تومان می باشد " }) @IsNumber() @ApiProperty({ type: "number", description: "the price of product in toman", example: 5432510 }) retail_price: number;