add auth roles and guards 050220
This commit is contained in:
@@ -7,8 +7,15 @@ import {
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { BusinessEntity } from '../../entities/business.entity';
|
||||
import { UserRole } from '../../entities/user.entity';
|
||||
import { AuthUser } from '../auth/auth.types';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '../auth/guards/roles.guard';
|
||||
import { BusinessesService } from './businesses.service';
|
||||
import { CreateBusinessDto } from './dto/create-business.dto';
|
||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
@@ -37,19 +44,26 @@ export class BusinessesController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
create(@Body() payload: CreateBusinessDto): Promise<BusinessEntity> {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN, UserRole.BUSINESS_OWNER)
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Body() payload: UpdateBusinessDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
): Promise<BusinessEntity> {
|
||||
return this.service.update(id, payload);
|
||||
return this.service.update(id, payload, user);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.ADMIN)
|
||||
async remove(@Param('id') id: string): Promise<{ success: true }> {
|
||||
await this.service.remove(id);
|
||||
return { success: true };
|
||||
|
||||
Reference in New Issue
Block a user