Files
shop-api/src/modules/admin/controllers/shop.controller.ts
T
2025-10-26 16:50:17 +03:30

84 lines
3.9 KiB
TypeScript

import { Request } from "express";
import { inject } from "inversify";
import { controller, httpGet, httpPatch, httpPost, request, requestBody, requestParam } from "inversify-express-utils";
import { HttpStatus } from "../../../common";
import { BaseController } from "../../../common/base/controller";
import { ApiAuth, ApiModel, ApiOperation, ApiParam, ApiResponse, ApiTags } from "../../../common/decorator/swggerDocs";
import { Guard } from "../../../core/middlewares/guard.middleware";
import { ValidationMiddleware } from "../../../core/middlewares/validator.middleware";
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";
@ApiTags("Admin Shop")
@controller("/admin/shop")
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
@ApiOperation("first step to create a single product for shop ==> need to login as admin")
@ApiResponse("successfully", HttpStatus.Created)
@ApiModel(ProductStepOneDTO)
@ApiParam("shopId", "id of shop")
@ApiAuth()
@httpPost("/:shopId/creation/detail", Guard.authAdmin(), ValidationMiddleware.validateInput(ProductStepOneDTO))
public async createProductForShop(@requestBody() createProductStepOneDto: ProductStepOneDTO, @requestParam("shopId") shopId: string) {
const data = await this.productService.createProductForShopS(createProductStepOneDto, shopId);
return this.response({ data }, HttpStatus.Created);
}
@ApiOperation("second step to create a single product for shop ==> need to login as admin")
@ApiResponse("successfully", HttpStatus.Created)
@ApiModel(ProductStepTwoDTO)
@ApiParam("shopId", "id of shop")
@ApiAuth()
@httpPost("/:shopId/creation/attribute", Guard.authAdmin(), ValidationMiddleware.validateInput(ProductStepTwoDTO))
public async createProductStepTwoForShop(
@requestBody() createProductStepTwoDto: ProductStepTwoDTO,
@requestParam("shopId") shopId: string,
) {
const data = await this.productService.createProductStepTwoForShopS(createProductStepTwoDto, shopId);
return this.response({ data }, HttpStatus.Created);
}
@ApiOperation("final step to create a single product for shop ==> need to login as admin")
@ApiResponse("successfully", HttpStatus.Created)
@ApiModel(ProductFinalStepDTO)
@ApiParam("shopId", "id of shop")
@ApiAuth()
@httpPost("/:shopId/creation/save", Guard.authAdmin(), ValidationMiddleware.validateInput(ProductFinalStepDTO))
public async createProductFinalStepForShop(
@requestBody() createProductFinalStepDto: ProductFinalStepDTO,
@requestParam("shopId") shopId: string,
) {
const data = await this.productService.createProductFinalStepForShopS(createProductFinalStepDto, shopId);
return this.response({ data }, HttpStatus.Created);
}
@ApiOperation("change status of shop chat")
@ApiAuth()
@httpPatch("/chat/status", Guard.authAdmin())
public async changeShopChatStatus(@request() req: Request) {
const admin = req.user as IAdmin;
const data = await this.adminService.changeShopChatStatus(admin._id.toString());
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);
}
//###############################################################
}