get rest admina
This commit is contained in:
@@ -14,11 +14,11 @@ import { CreateMyRestaurantAdminDto } from '../dto/create-my-restaurant-admin.dt
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('admin')
|
||||
@Controller('admin/admins')
|
||||
@Controller()
|
||||
export class AdminController {
|
||||
constructor(private readonly adminService: AdminService) { }
|
||||
|
||||
@Get()
|
||||
@Get('admin/admins')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'admin' })
|
||||
@@ -27,7 +27,7 @@ export class AdminController {
|
||||
return admin;
|
||||
}
|
||||
|
||||
@Get('profile')
|
||||
@Get('admin/admins/profile')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'admin' })
|
||||
@@ -36,7 +36,7 @@ export class AdminController {
|
||||
return admin;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Post('admin/admins')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@@ -47,7 +47,7 @@ export class AdminController {
|
||||
return admin;
|
||||
}
|
||||
|
||||
@Patch(':adminId')
|
||||
@Patch('admin/admins/:adminId')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'Update an admin' })
|
||||
@@ -57,7 +57,7 @@ export class AdminController {
|
||||
return this.adminService.update(adminId, restId, dto);
|
||||
}
|
||||
|
||||
@Get(':adminId')
|
||||
@Get('admin/admins/:adminId')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'Get an admin by ID' })
|
||||
@@ -66,7 +66,7 @@ export class AdminController {
|
||||
return this.adminService.findById(adminId, restId);
|
||||
}
|
||||
|
||||
@Delete(':adminId')
|
||||
@Delete('admin/admins/:adminId')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'Delete an admin by ID' })
|
||||
@@ -76,6 +76,17 @@ export class AdminController {
|
||||
}
|
||||
|
||||
/** Super Admin Endpoints */
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
@Get('super-admin/restaurants/:restaurantId/admins')
|
||||
@ApiOperation({ summary: 'Get admins for a specific restaurant (Super Admin only)' })
|
||||
@ApiParam({ name: 'restaurantId', description: 'Restaurant ID' })
|
||||
|
||||
getAdminForRestaurant(
|
||||
@Param('restaurantId') restaurantId: string,
|
||||
): Promise<Admin[]> {
|
||||
return this.adminService.getAdminsForRestaurantBySuperAdmin(restaurantId);
|
||||
}
|
||||
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
@Post('super-admin/restaurants/:restaurantId/admins')
|
||||
@ApiOperation({ summary: 'Create admin for a specific restaurant (Super Admin only)' })
|
||||
|
||||
@@ -119,6 +119,13 @@ export class AdminService {
|
||||
return admin;
|
||||
}
|
||||
|
||||
async getAdminsForRestaurantBySuperAdmin(restId: string): Promise<Admin[]> {
|
||||
const restaurant = await this.em.findOne(Restaurant, { id: restId });
|
||||
if (!restaurant) throw new NotFoundException('Restaurant not found');
|
||||
|
||||
return this.adminRepository.find({ roles: { restaurant: restaurant } }, { populate: ['roles', 'roles.role'] });
|
||||
}
|
||||
|
||||
async update(adminId: string, restId: string, dto: UpdateAdminDto): Promise<Admin> {
|
||||
const admin = await this.adminRepository.findOne(
|
||||
{ id: adminId, roles: { restaurant: { id: restId } } },
|
||||
|
||||
Reference in New Issue
Block a user