add: update admin route added

This commit is contained in:
morteza-mortezai
2025-10-27 10:59:41 +03:30
parent 9af567c91a
commit c4a60ae813
2 changed files with 53 additions and 0 deletions
+37
View File
@@ -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;
}
@@ -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()