import { Controller, Post, Body, HttpCode, HttpStatus, Get, UseGuards, Patch, Param, Delete } from '@nestjs/common'; import { AdminService } from '../providers/admin.service'; import { CreateAdminDto } from '../dto/create-admin.dto'; import { UpdateAdminDto } from '../dto/update-admin.dto'; import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth, ApiParam } 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'; import { Admin } from '../entities/admin.entity'; @UseGuards(AdminAuthGuard) @ApiBearerAuth() @ApiTags('admin') @Controller('admin/admins') export class AdminController { constructor(private readonly adminService: AdminService) {} @Get() @ApiOperation({ summary: 'admin' }) async getAll(@RestId() restId: string) { const admin = await this.adminService.findAllByRestaurantId(restId); return admin; } @Get('profile') @ApiOperation({ summary: 'admin' }) async getMe(@AdminId() adminId: string, @RestId() restId: string) { const admin = await this.adminService.findById(adminId, restId); return admin; } @Post() @HttpCode(HttpStatus.CREATED) @ApiOperation({ summary: 'Create a new admin' }) @ApiBody({ type: CreateAdminDto }) async create(@Body() dto: CreateAdminDto, @RestId() restId: string) { const admin = await this.adminService.createAdminForMyRestaurant(restId, dto); return admin; } @Patch(':adminId') @ApiOperation({ summary: 'Update an admin' }) @ApiParam({ name: 'adminId', description: 'Admin ID' }) @ApiBody({ type: UpdateAdminDto }) update(@Param('adminId') adminId: string, @Body() dto: UpdateAdminDto, @RestId() restId: string): Promise { return this.adminService.update(adminId, restId, dto); } @Get(':adminId') @ApiOperation({ summary: 'Get an admin by ID' }) @ApiParam({ name: 'id', description: 'Admin ID' }) getById(@Param('adminId') adminId: string, @RestId() restId: string): Promise { return this.adminService.findById(adminId, restId); } @Delete(':adminId') @ApiOperation({ summary: 'Delete an admin by ID' }) @ApiParam({ name: 'id', description: 'Admin ID' }) deleteById(@Param('adminId') adminId: string, @RestId() restId: string): Promise { return this.adminService.remove(adminId, restId); } }