Merge pull request #26 from Danakcorp/mrtz

Mrtz
This commit is contained in:
morteza-mortezai
2025-10-26 16:58:17 +03:30
committed by GitHub
5 changed files with 66 additions and 4 deletions
@@ -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);
}
}
@@ -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);
}
//###############################################################
}
+1 -1
View File
@@ -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;
+23
View File
@@ -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);
+5 -1
View File
@@ -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<IShop> {
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 {