Add AdminId decorator for extracting adminId from requests; refactor AdminController to utilize new decorator for fetching admin details and restaurant-specific admins; update AdminService to handle admin creation and retrieval by restaurant; remove unused role and permission entities for cleaner architecture.

This commit is contained in:
2025-11-18 16:45:44 +03:30
parent 9abab789fc
commit 8a217f6034
18 changed files with 254 additions and 206 deletions
@@ -3,6 +3,8 @@ import { AdminService } from '../providers/admin.service';
import { CreateAdminDto } from '../dto/create-admin.dto';
import { ApiTags, ApiOperation, ApiBody, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { RestId } from 'src/common/decorators';
import { AdminId } from 'src/common/decorators/admin-id.decorator';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@@ -11,19 +13,19 @@ import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
export class AdminController {
constructor(private readonly adminService: AdminService) {}
@Get()
@Get('my-restaurant-admins')
@ApiOperation({ summary: 'admin' })
@ApiResponse({ status: 201, description: 'Admins' })
async getAll() {
const admin = await this.adminService.findAll();
async getAll(@RestId() restId: string) {
const admin = await this.adminService.findAllByRestaurantId(restId);
return admin;
}
@Get('me')
@ApiOperation({ summary: 'admin' })
@ApiResponse({ status: 201, description: 'Admins' })
async getMe() {
const admin = await this.adminService.findAll();
async getMe(@AdminId() adminId: string) {
const admin = await this.adminService.findById(adminId);
return admin;
}
@@ -33,7 +35,7 @@ export class AdminController {
@ApiBody({ type: CreateAdminDto })
@ApiResponse({ status: 201, description: 'Admin created' })
async create(@Body() dto: CreateAdminDto) {
const admin = await this.adminService.create({
const admin = await this.adminService.createRestaurantBySuperAdmin({
phone: dto.phone,
firstName: dto.firstName,
lastName: dto.lastName,