@@ -2,6 +2,7 @@ import { Controller, Post, Body, Get, UseGuards, Patch, Param, Delete } from '@n
|
|||||||
import { AdminService } from '../providers/admin.service';
|
import { AdminService } from '../providers/admin.service';
|
||||||
import { CreateAdminDto } from '../dto/create-admin.dto';
|
import { CreateAdminDto } from '../dto/create-admin.dto';
|
||||||
import { UpdateAdminDto } from '../dto/update-admin.dto';
|
import { UpdateAdminDto } from '../dto/update-admin.dto';
|
||||||
|
import { UpdateAdminMeDto } from '../dto/update-admin-me.dto';
|
||||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||||
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
||||||
@@ -38,13 +39,18 @@ export class AdminController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('admin/admins/me')
|
@Get('admin/admins/me')
|
||||||
@Permissions(PermissionEnum.MANAGE_ADMINS)
|
@ApiOperation({ summary: 'Get current authenticated admin profile' })
|
||||||
@ApiOperation({ summary: 'admin' })
|
|
||||||
async getMe(@AdminId() adminId: string,) {
|
async getMe(@AdminId() adminId: string,) {
|
||||||
const admin = await this.adminService.findById(adminId,);
|
const admin = await this.adminService.findById(adminId,);
|
||||||
return admin;
|
return admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Patch('admin/admins/me')
|
||||||
|
@ApiOperation({ summary: 'Update current authenticated admin profile' })
|
||||||
|
updateMe(@AdminId() adminId: string, @Body() dto: UpdateAdminMeDto,): Promise<Admin> {
|
||||||
|
return this.adminService.updateMe(adminId, dto);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('admin/dashboard/counts')
|
@Get('admin/dashboard/counts')
|
||||||
@ApiOperation({ summary: 'Get dashboard entity counts for admin panel' })
|
@ApiOperation({ summary: 'Get dashboard entity counts for admin panel' })
|
||||||
getDashboardCounts() {
|
getDashboardCounts() {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsMobilePhone, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class UpdateAdminMeDto {
|
||||||
|
@ApiProperty({ description: 'Mobile phone number', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@IsMobilePhone('fa-IR')
|
||||||
|
phone?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'First name', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
firstName?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'Last name', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
lastName?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'Avatar S3 key', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
avatarUrl?: string;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { Admin } from '../entities/admin.entity';
|
|||||||
import { Role } from '../../roles/entities/role.entity';
|
import { Role } from '../../roles/entities/role.entity';
|
||||||
import { EntityManager } from '@mikro-orm/postgresql';
|
import { EntityManager } from '@mikro-orm/postgresql';
|
||||||
import { UpdateAdminDto } from '../dto/update-admin.dto';
|
import { UpdateAdminDto } from '../dto/update-admin.dto';
|
||||||
|
import { UpdateAdminMeDto } from '../dto/update-admin-me.dto';
|
||||||
import { CreateAdminDto } from '../dto/create-admin.dto';
|
import { CreateAdminDto } from '../dto/create-admin.dto';
|
||||||
import { AdminRepository } from '../repositories/admin.repository';
|
import { AdminRepository } from '../repositories/admin.repository';
|
||||||
import { RoleRepository } from 'src/modules/roles/respository/role.repository';
|
import { RoleRepository } from 'src/modules/roles/respository/role.repository';
|
||||||
@@ -73,6 +74,10 @@ export class AdminService {
|
|||||||
return this.adminRepository.find({}, { populate: ['role'] });
|
return this.adminRepository.find({}, { populate: ['role'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateMe(adminId: string, dto: UpdateAdminMeDto): Promise<Admin> {
|
||||||
|
return this.update(adminId, dto);
|
||||||
|
}
|
||||||
|
|
||||||
async update(adminId: string, dto: UpdateAdminDto): Promise<Admin> {
|
async update(adminId: string, dto: UpdateAdminDto): Promise<Admin> {
|
||||||
const admin = await this.adminRepository.findOne(
|
const admin = await this.adminRepository.findOne(
|
||||||
{ id: adminId },
|
{ id: adminId },
|
||||||
|
|||||||
Reference in New Issue
Block a user