diff --git a/src/modules/admin/DTO/upateAdmin.dto.ts b/src/modules/admin/DTO/upateAdmin.dto.ts new file mode 100644 index 0000000..b7960da --- /dev/null +++ b/src/modules/admin/DTO/upateAdmin.dto.ts @@ -0,0 +1,37 @@ +import { Expose } from "class-transformer"; +import { IsNotEmpty } from "class-validator"; + +import { ApiProperty } from "../../../common/decorator/swggerDocs"; +import { AdminMessage, RoleMessage } from "../../../common/enums/message.enum"; + +export class UpdateAdminDTO { + @Expose() + @IsNotEmpty({ message: AdminMessage.FullNameNotEmpty }) + @ApiProperty({ type: "string", description: "full name of new admin", example: "admin 1" }) + fullName: string; + + @Expose() + @IsNotEmpty({ message: AdminMessage.UserNameNotEmpty }) + @ApiProperty({ type: "string", description: "username of new admin", example: "admin1" }) + userName: string; + + @Expose() + @IsNotEmpty({ message: AdminMessage.EmailNotEmpty }) + @ApiProperty({ type: "string", description: "email of new admin", example: "admin1@gmail.com" }) + email: string; + + @Expose() + @IsNotEmpty({ message: AdminMessage.PhoneNotEmpty }) + @ApiProperty({ type: "string", description: "phoneNumber of new admin", example: "09918914108" }) + phoneNumber: string; + + @Expose() + @IsNotEmpty({ message: RoleMessage.PermissionsNotEmpty }) + @ApiProperty({ type: "array", description: "permissions of user", example: ["67723b0c8109df157bd9b2c0", "67723b0c8109df157bd9b2ba"] }) + permissions: string[]; + + @Expose() + @IsNotEmpty({ message: AdminMessage.PasswordNotEmpty }) + @ApiProperty({ type: "string", description: "password", example: "123@123!" }) + password: string; +} diff --git a/src/modules/admin/controllers/admin.controller.ts b/src/modules/admin/controllers/admin.controller.ts index 1bbb9b7..96d69f5 100644 --- a/src/modules/admin/controllers/admin.controller.ts +++ b/src/modules/admin/controllers/admin.controller.ts @@ -101,6 +101,22 @@ export class AdminBaseController extends BaseController { return this.response(data); } + @ApiOperation("Update new admin") + @ApiResponse("successfully", HttpStatus.Created) + @ApiModel(CreateAdminDTO) + @ApiAuth() + @httpPost( + "/create", + Guard.authAdmin(), + Guard.checkAdminPermissions([PermissionEnum.ADMIN]), + ValidationMiddleware.validateInput(CreateAdminDTO), + ) + public async updateAdmin(@request() req: Request, @requestBody() createDto: CreateAdminDTO) { + const admin = req.user as IAdmin; + const data = await this.adminService.createAdminS(admin._id.toString(), createDto); + return this.response(data); + } + @ApiOperation("delete admin") @ApiResponse("successfully", HttpStatus.Ok) @ApiAuth() diff --git a/src/modules/admin/controllers/shipment.controller.ts b/src/modules/admin/controllers/shipment.controller.ts index 3b6c475..ce4632a 100644 --- a/src/modules/admin/controllers/shipment.controller.ts +++ b/src/modules/admin/controllers/shipment.controller.ts @@ -33,6 +33,26 @@ export class AdminShipmentController extends BaseController { return this.response({ data }, HttpStatus.Created); } + @ApiOperation("activate the admin shop shipment method") + @ApiModel(UpdateShopShipmentDTO) + @ApiAuth() + @httpPatch("/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("/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); + } + @ApiOperation("update a shipment provider") @ApiResponse("successful", HttpStatus.Ok) @ApiParam("id", "shipment provider id", true) @@ -63,24 +83,4 @@ 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); - } }