This commit is contained in:
mahyargdz
2025-09-14 15:15:03 +03:30
commit be82059172
534 changed files with 51310 additions and 0 deletions
@@ -0,0 +1,133 @@
import { inject } from "inversify";
import { controller, httpDelete, httpGet, httpPatch, queryParam, requestBody, requestParam } from "inversify-express-utils";
import { BaseController } from "../../../common/base/controller";
import { ApiAuth, ApiModel, ApiOperation, ApiParam, ApiQuery, ApiTags } from "../../../common/decorator/swggerDocs";
import { PaginationDTO } from "../../../common/dto/pagination.dto";
import { ParamDto } from "../../../common/dto/param.dto";
import { Guard } from "../../../core/middlewares/guard.middleware";
import { ValidationMiddleware } from "../../../core/middlewares/validator.middleware";
import { IOCTYPES } from "../../../IOC/ioc.types";
import { SellerService } from "../../seller/seller.service";
import { UserService } from "../../user/user.service";
import { RejectReasonSellerDocumentDto, UpdateSellerDocumentDto } from "../DTO/updateSellerDocument.dto";
@ApiTags("Admin Users managements")
@controller("/admin")
export class AdminUsersController extends BaseController {
@inject(IOCTYPES.SellerService) private sellerService: SellerService;
@inject(IOCTYPES.UserService) private userService: UserService;
@ApiOperation("get all sellers")
@ApiQuery("page", "page number", false)
@ApiQuery("limit", "limit per page", false)
@ApiAuth()
@httpGet("/sellers", Guard.authAdmin(), ValidationMiddleware.validateQuery(PaginationDTO))
public async getSellers(@queryParam() queryDto: PaginationDTO) {
const { count, sellers } = await this.sellerService.getSellersWithDocumentsAndContracts(queryDto);
const { pager } = this.paginate(count);
return this.response({ sellers, pager });
}
@ApiOperation("get all wholesale requests")
@ApiQuery("page", "page number", false)
@ApiQuery("limit", "limit per page", false)
@ApiAuth()
@httpGet("/sellers/wholesale-requests", Guard.authAdmin(), ValidationMiddleware.validateQuery(PaginationDTO))
public async getWholesaleRequests(@queryParam() queryDto: PaginationDTO) {
const { count, requests } = await this.sellerService.getWholesaleRequests(queryDto);
const { pager } = this.paginate(count);
return this.response({ requests, pager });
}
@ApiOperation("get single seller")
@ApiParam("id", "the seller id", true)
@ApiAuth()
@httpGet("/sellers/:id", Guard.authAdmin(), ValidationMiddleware.validateParameter(ParamDto))
public async getSingleSeller(@requestParam() paramDto: ParamDto) {
const data = await this.sellerService.getSellerById(paramDto.id);
return this.response(data);
}
@ApiOperation("approve seller wholesale")
@ApiParam("id", "the seller id", true)
@ApiAuth()
@httpPatch("/sellers/wholesale-requests/:id", Guard.authAdmin(), ValidationMiddleware.validateParameter(ParamDto))
public async approveSellerWholesale(@requestParam() paramDto: ParamDto) {
const data = await this.sellerService.approveSellerWholesale(paramDto.id);
return this.response(data);
}
@ApiOperation("approve seller registration")
@ApiParam("id", "the seller id", true)
@ApiAuth()
@httpPatch("/sellers/approve-register/:id", Guard.authAdmin(), ValidationMiddleware.validateParameter(ParamDto))
public async approveSellerRegistration(@requestParam() paramDto: ParamDto) {
const data = await this.sellerService.approveSellerRegistration(paramDto.id);
return this.response(data);
}
@ApiOperation("approve seller contract")
@ApiParam("id", "the seller id", true)
@ApiAuth()
@httpPatch("/sellers/approve-contract/:id", Guard.authAdmin(), ValidationMiddleware.validateParameter(ParamDto))
public async approveSellerContract(@requestParam() paramDto: ParamDto) {
const data = await this.sellerService.approveSellerContract(paramDto.id);
return this.response(data);
}
@ApiOperation("approve seller document")
@ApiParam("id", "the seller id", true)
@ApiModel(UpdateSellerDocumentDto)
@ApiAuth()
@httpPatch(
"/sellers/document/:id",
Guard.authAdmin(),
ValidationMiddleware.validateParameter(ParamDto),
ValidationMiddleware.validateInput(UpdateSellerDocumentDto),
)
public async approveSellerDocs(@requestParam() paramDto: ParamDto, @requestBody() updateDto: UpdateSellerDocumentDto) {
const data = await this.sellerService.updateSellerDocumentStatus(paramDto.id, updateDto);
return this.response(data);
}
@ApiOperation("delete seller document")
@ApiParam("id", "the document id", true)
@ApiModel(RejectReasonSellerDocumentDto)
@ApiAuth()
@httpDelete(
"/sellers/document/:id",
Guard.authAdmin(),
ValidationMiddleware.validateParameter(ParamDto),
ValidationMiddleware.validateInput(RejectReasonSellerDocumentDto),
)
public async deleteSellerDocs(@requestParam() paramDto: ParamDto, @requestBody() rejectDto: RejectReasonSellerDocumentDto) {
const data = await this.sellerService.deleteSellerDocument(paramDto.id, rejectDto.reason);
return this.response(data);
}
// @ApiOperation("get all seller documents")
// @ApiAuth()
// @httpGet("/sellers/documents", Guard.authAdmin())
// public async getSellerDocuments() {}
@ApiOperation("get all users")
@ApiQuery("page", "page number", false)
@ApiQuery("limit", "limit per page", false)
@ApiAuth()
@httpGet("/users", Guard.authAdmin(), ValidationMiddleware.validateQuery(PaginationDTO))
public async getUsers(@queryParam() queryDto: PaginationDTO) {
const { count, users } = await this.userService.getAllUsers(queryDto);
const { pager } = this.paginate(count);
return this.response({ users, pager });
}
@ApiOperation("get single user")
@ApiParam("id", "the user id", true)
@ApiAuth()
@httpGet("/users/:id", Guard.authAdmin(), ValidationMiddleware.validateParameter(ParamDto))
public async getSingleUser(@requestParam() paramDto: ParamDto) {
const data = await this.userService.getUserById(paramDto.id);
return this.response(data);
}
}