first
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { Request } from "express";
|
||||
import { inject } from "inversify";
|
||||
import { controller, httpGet, httpPost, queryParam, request, requestBody } from "inversify-express-utils";
|
||||
|
||||
import { ShipmentService } from "./shipment.service";
|
||||
import { HttpStatus } from "../../common";
|
||||
import { SaveSellerShipmentInfoDTO } from "./DTO/calculateShipCost.dto";
|
||||
import { BaseController } from "../../common/base/controller";
|
||||
import { ApiAuth, ApiModel, ApiOperation, ApiQuery, 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 { IUser } from "../user/models/Abstraction/IUser";
|
||||
|
||||
@controller("/shipment")
|
||||
@ApiTags("Shipment")
|
||||
class ShipmentController extends BaseController {
|
||||
@inject(IOCTYPES.ShipmentService) shipmentService: ShipmentService;
|
||||
//
|
||||
|
||||
@ApiOperation("get list of all shipment provider")
|
||||
@ApiResponse("successful", HttpStatus.Ok)
|
||||
@ApiQuery("limit", "the limit of return data")
|
||||
@ApiQuery("page", "the page want to get")
|
||||
@httpGet("")
|
||||
public async getShipmentProviders(@queryParam("limit") limit: string, @queryParam("page") page: string) {
|
||||
const queries = {
|
||||
limit: parseInt(limit),
|
||||
page: parseInt(page),
|
||||
};
|
||||
const { count, shipper } = await this.shipmentService.getAllProviders(queries);
|
||||
const { pager } = this.paginate(count);
|
||||
return this.response({ pager, shipper });
|
||||
}
|
||||
|
||||
@ApiOperation("Calculate shipment cost for checkout")
|
||||
@ApiResponse("Successful", HttpStatus.Ok)
|
||||
@ApiAuth()
|
||||
@httpGet("/shipping-cost", Guard.authUser())
|
||||
public async calculateShipCost(@request() req: Request) {
|
||||
const user = req.user as IUser;
|
||||
const data = await this.shipmentService.calculateAllShipmentOptions(user._id.toString());
|
||||
return this.response(data);
|
||||
}
|
||||
|
||||
@ApiOperation("save shipment info for checkout")
|
||||
@ApiResponse("Successful", HttpStatus.Ok)
|
||||
@ApiModel(SaveSellerShipmentInfoDTO)
|
||||
@ApiAuth()
|
||||
@httpPost("/save", Guard.authUser(), ValidationMiddleware.validateInput(SaveSellerShipmentInfoDTO))
|
||||
public async saveShipment(@requestBody() saveShippingInfo: SaveSellerShipmentInfoDTO, @request() req: Request) {
|
||||
const user = req.user as IUser;
|
||||
const data = await this.shipmentService.selectShipmentProvider(saveShippingInfo, user._id.toString());
|
||||
return this.response(data);
|
||||
}
|
||||
}
|
||||
|
||||
export { ShipmentController };
|
||||
Reference in New Issue
Block a user