From c4a60ae81367a323d10044395d8d8dded5c4dcaf Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Mon, 27 Oct 2025 10:59:41 +0330 Subject: [PATCH] add: update admin route added --- src/modules/admin/DTO/upateAdmin.dto.ts | 37 +++++++++++++++++++ .../admin/controllers/admin.controller.ts | 16 ++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/modules/admin/DTO/upateAdmin.dto.ts 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()