admin
This commit is contained in:
@@ -2,7 +2,7 @@ import { Controller, Post, Body, HttpCode, HttpStatus, Get, UseGuards, Patch, Pa
|
|||||||
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 { ApiTags, ApiOperation, ApiBody, ApiBearerAuth, ApiParam, ApiHeader } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
|
||||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||||
import { SuperAdminAuthGuard } from 'src/modules/auth/guards/superAdminAuth.guard';
|
import { SuperAdminAuthGuard } from 'src/modules/auth/guards/superAdminAuth.guard';
|
||||||
import { RestId } from 'src/common/decorators';
|
import { RestId } from 'src/common/decorators';
|
||||||
@@ -16,7 +16,7 @@ import { CreateMyRestaurantAdminDto } from '../dto/create-my-restaurant-admin.dt
|
|||||||
@ApiTags('admin')
|
@ApiTags('admin')
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AdminController {
|
export class AdminController {
|
||||||
constructor(private readonly adminService: AdminService) { }
|
constructor(private readonly adminService: AdminService) {}
|
||||||
|
|
||||||
@Get('admin/admins')
|
@Get('admin/admins')
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@@ -80,10 +80,7 @@ export class AdminController {
|
|||||||
@Get('super-admin/restaurants/:restaurantId/admins')
|
@Get('super-admin/restaurants/:restaurantId/admins')
|
||||||
@ApiOperation({ summary: 'Get admins for a specific restaurant (Super Admin only)' })
|
@ApiOperation({ summary: 'Get admins for a specific restaurant (Super Admin only)' })
|
||||||
@ApiParam({ name: 'restaurantId', description: 'Restaurant ID' })
|
@ApiParam({ name: 'restaurantId', description: 'Restaurant ID' })
|
||||||
|
getAdminForRestaurant(@Param('restaurantId') restaurantId: string): Promise<Admin[]> {
|
||||||
getAdminForRestaurant(
|
|
||||||
@Param('restaurantId') restaurantId: string,
|
|
||||||
): Promise<Admin[]> {
|
|
||||||
return this.adminService.getAdminsForRestaurantBySuperAdmin(restaurantId);
|
return this.adminService.getAdminsForRestaurantBySuperAdmin(restaurantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export class AdminService {
|
|||||||
private readonly adminRoleRepository: EntityRepository<AdminRole>,
|
private readonly adminRoleRepository: EntityRepository<AdminRole>,
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
private readonly cacheService: CacheService,
|
private readonly cacheService: CacheService,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
async findByPhone(phone: string): Promise<Admin | null> {
|
async findByPhone(phone: string): Promise<Admin | null> {
|
||||||
const normalizedPhone = normalizePhone(phone);
|
const normalizedPhone = normalizePhone(phone);
|
||||||
@@ -94,8 +94,8 @@ export class AdminService {
|
|||||||
});
|
});
|
||||||
await this.em.persistAndFlush(admin);
|
await this.em.persistAndFlush(admin);
|
||||||
}
|
}
|
||||||
const role = await this.em.findOne(Role, { id: roleId, isSystem: false });
|
const role = await this.em.findOne(Role, { id: roleId });
|
||||||
if (!role) throw new NotFoundException('Role not found');
|
if (!role) throw new NotFoundException('Role* not found' + roleId);
|
||||||
|
|
||||||
const restaurant = await this.em.findOne(Restaurant, { id: restId });
|
const restaurant = await this.em.findOne(Restaurant, { id: restId });
|
||||||
if (!restaurant) throw new NotFoundException('Restaurant not found');
|
if (!restaurant) throw new NotFoundException('Restaurant not found');
|
||||||
|
|||||||
Reference in New Issue
Block a user