Skip to content

Commit a77103d

Browse files
committed
2 parents 6d39669 + 45aa990 commit a77103d

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"info": {
3+
"_postman_id": "4e1c5db9-7570-46ce-88d3-ff74c6f4f28e",
4+
"name": "Seguridad",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
6+
"_exporter_id": "11708390"
7+
},
8+
"item": [
9+
{
10+
"name": "Obtener token",
11+
"request": {
12+
"method": "POST",
13+
"header": [],
14+
"body": {
15+
"mode": "raw",
16+
"raw": "{\r\n \"username\": \"lecturaNegocio\",\r\n \"password\": \"lecturaNegocio\"\r\n}",
17+
"options": {
18+
"raw": {
19+
"language": "json"
20+
}
21+
}
22+
},
23+
"url": {
24+
"raw": "{{baseUrl}}/users/login",
25+
"host": [
26+
"{{baseUrl}}"
27+
],
28+
"path": [
29+
"users",
30+
"login"
31+
]
32+
}
33+
},
34+
"response": []
35+
}
36+
]
37+
}

src/evento/evento.controller.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,48 @@ import {
88
Param,
99
Post,
1010
Put,
11+
UseGuards,
1112
UseInterceptors,
1213
} from '@nestjs/common';
1314
import { plainToInstance } from 'class-transformer';
1415
import { BusinessErrorsInterceptor } from '../shared/interceptors/business-errors.interceptor';
1516
import { EventoDto } from './evento.dto';
1617
import { EventoEntity } from './evento.entity';
1718
import { EventoService } from './evento.service';
19+
import { HasRoles } from '../auth/has-roles.decorator';
20+
import { Role } from '../auth/role.enum';
21+
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
22+
import { RolesGuard } from 'src/auth/roles.guard';
1823

1924
@Controller('eventos')
2025
@UseInterceptors(BusinessErrorsInterceptor)
2126
export class EventoController {
2227
constructor(private readonly eventoService: EventoService) {}
2328

29+
@HasRoles(Role.AdminEvento, Role.LecturaEvento)
30+
@UseGuards(JwtAuthGuard, RolesGuard)
2431
@Get()
2532
async findAll() {
2633
return await this.eventoService.findAll();
2734
}
2835

36+
@HasRoles(Role.AdminEvento, Role.LecturaEvento)
37+
@UseGuards(JwtAuthGuard, RolesGuard)
2938
@Get(':eventoId')
3039
async findOne(@Param('eventoId') eventoId: string) {
3140
return await this.eventoService.findOne(eventoId);
3241
}
3342

43+
@HasRoles(Role.AdminEvento, Role.EscrituraEvento)
44+
@UseGuards(JwtAuthGuard, RolesGuard)
3445
@Post()
3546
async create(@Body() eventoDto: EventoDto) {
3647
const evento: EventoEntity = plainToInstance(EventoEntity, eventoDto);
3748
return await this.eventoService.create(evento);
3849
}
3950

51+
@HasRoles(Role.AdminEvento, Role.EscrituraEvento)
52+
@UseGuards(JwtAuthGuard, RolesGuard)
4053
@Put(':eventoId')
4154
async update(
4255
@Param('eventoId') eventoId: string,
@@ -46,6 +59,8 @@ export class EventoController {
4659
return await this.eventoService.update(eventoId, evento);
4760
}
4861

62+
@HasRoles(Role.AdminEvento, Role.EliminarEvento)
63+
@UseGuards(JwtAuthGuard, RolesGuard)
4964
@Delete(':eventoId')
5065
@HttpCode(204)
5166
async delete(@Param('eventoId') eventoId: string) {

src/review-producto/review-producto.controller.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@ import {
88
Param,
99
Post,
1010
Put,
11+
UseGuards,
1112
UseInterceptors,
1213
} from '@nestjs/common';
1314
import { plainToInstance } from 'class-transformer';
1415
import { ReviewDto } from 'src/review/review.dto';
1516
import { ReviewEntity } from 'src/review/review.entity';
1617
import { BusinessErrorsInterceptor } from '../shared/interceptors/business-errors.interceptor';
1718
import { ReviewProductoService } from './review-producto.service';
19+
import { HasRoles } from '../auth/has-roles.decorator';
20+
import { Role } from '../auth/role.enum';
21+
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
22+
import { RolesGuard } from 'src/auth/roles.guard';
1823

1924
@Controller('productos')
2025
@UseInterceptors(BusinessErrorsInterceptor)
2126
export class ReviewProductoController {
2227
constructor(private readonly reviewProductoService: ReviewProductoService) {}
2328

29+
@HasRoles(
30+
Role.AdminReview,
31+
Role.EscrituraReview,
32+
Role.AdminProducto,
33+
Role.EscrituraProducto,
34+
)
35+
@UseGuards(JwtAuthGuard, RolesGuard)
2436
@Post(':productoId/reviews/:reviewId')
2537
async addReviewProducto(
2638
@Param('productoId') productoId: string,
@@ -32,6 +44,13 @@ export class ReviewProductoController {
3244
);
3345
}
3446

47+
@HasRoles(
48+
Role.AdminReview,
49+
Role.LecturaReview,
50+
Role.AdminProducto,
51+
Role.LecturaProducto,
52+
)
53+
@UseGuards(JwtAuthGuard, RolesGuard)
3554
@Get(':productoId/reviews/:reviewId')
3655
async findReviewByProductoIdReviewId(
3756
@Param('productoId') productoId: string,
@@ -43,11 +62,25 @@ export class ReviewProductoController {
4362
);
4463
}
4564

65+
@HasRoles(
66+
Role.AdminReview,
67+
Role.LecturaReview,
68+
Role.AdminProducto,
69+
Role.LecturaProducto,
70+
)
71+
@UseGuards(JwtAuthGuard, RolesGuard)
4672
@Get(':productoId/reviews')
4773
async findReviewsByProductoId(@Param('productoId') productoId: string) {
4874
return await this.reviewProductoService.findReviewsByProductoId(productoId);
4975
}
5076

77+
@HasRoles(
78+
Role.AdminReview,
79+
Role.EscrituraReview,
80+
Role.AdminProducto,
81+
Role.EscrituraProducto,
82+
)
83+
@UseGuards(JwtAuthGuard, RolesGuard)
5184
@Put(':productoId/reviews')
5285
async associateReviewsProducto(
5386
@Body() reviewsDto: ReviewDto[],
@@ -60,6 +93,13 @@ export class ReviewProductoController {
6093
);
6194
}
6295

96+
@HasRoles(
97+
Role.AdminReview,
98+
Role.EliminarReview,
99+
Role.AdminProducto,
100+
Role.EliminarProducto,
101+
)
102+
@UseGuards(JwtAuthGuard, RolesGuard)
63103
@Delete(':productoId/reviews/:reviewId')
64104
@HttpCode(204)
65105
async deleteReviewProducto(

src/review-usuario/review-usuario.controller.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@ import {
88
Param,
99
Post,
1010
Put,
11+
UseGuards,
1112
UseInterceptors,
1213
} from '@nestjs/common';
1314
import { plainToInstance } from 'class-transformer';
1415
import { ReviewDto } from 'src/review/review.dto';
1516
import { ReviewEntity } from 'src/review/review.entity';
1617
import { BusinessErrorsInterceptor } from '../shared/interceptors/business-errors.interceptor';
1718
import { ReviewUsuarioService } from './review-usuario.service';
19+
import { HasRoles } from '../auth/has-roles.decorator';
20+
import { Role } from '../auth/role.enum';
21+
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
22+
import { RolesGuard } from 'src/auth/roles.guard';
1823

1924
@Controller('usuarios')
2025
@UseInterceptors(BusinessErrorsInterceptor)
2126
export class ReviewUsuarioController {
2227
constructor(private readonly reviewUsuarioService: ReviewUsuarioService) {}
2328

29+
@HasRoles(
30+
Role.AdminReview,
31+
Role.EscrituraReview,
32+
Role.AdminUsuario,
33+
Role.EscrituraUsuario,
34+
)
35+
@UseGuards(JwtAuthGuard, RolesGuard)
2436
@Post(':usuarioId/reviews/:reviewId')
2537
async addReviewUsuario(
2638
@Param('usuarioId') usuarioId: string,
@@ -32,6 +44,13 @@ export class ReviewUsuarioController {
3244
);
3345
}
3446

47+
@HasRoles(
48+
Role.AdminReview,
49+
Role.LecturaReview,
50+
Role.AdminUsuario,
51+
Role.LecturaUsuario,
52+
)
53+
@UseGuards(JwtAuthGuard, RolesGuard)
3554
@Get(':usuarioId/reviews/:reviewId')
3655
async findReviewByUsuarioIdReviewId(
3756
@Param('usuarioId') usuarioId: string,
@@ -43,11 +62,25 @@ export class ReviewUsuarioController {
4362
);
4463
}
4564

65+
@HasRoles(
66+
Role.AdminReview,
67+
Role.LecturaReview,
68+
Role.AdminUsuario,
69+
Role.LecturaUsuario,
70+
)
71+
@UseGuards(JwtAuthGuard, RolesGuard)
4672
@Get(':usuarioId/reviews')
4773
async findReviewsByUsuarioId(@Param('usuarioId') usuarioId: string) {
4874
return await this.reviewUsuarioService.findReviewsByUsuarioId(usuarioId);
4975
}
5076

77+
@HasRoles(
78+
Role.AdminReview,
79+
Role.EscrituraReview,
80+
Role.AdminUsuario,
81+
Role.EscrituraUsuario,
82+
)
83+
@UseGuards(JwtAuthGuard, RolesGuard)
5184
@Put(':usuarioId/reviews')
5285
async associateReviewsUsuario(
5386
@Body() reviewsDto: ReviewDto[],
@@ -60,6 +93,13 @@ export class ReviewUsuarioController {
6093
);
6194
}
6295

96+
@HasRoles(
97+
Role.AdminReview,
98+
Role.EliminarReview,
99+
Role.AdminUsuario,
100+
Role.EliminarUsuario,
101+
)
102+
@UseGuards(JwtAuthGuard, RolesGuard)
63103
@Delete(':usuarioId/reviews/:reviewId')
64104
@HttpCode(204)
65105
async deleteReviewUsuario(

src/review/review.controller.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,48 @@ import {
88
Param,
99
Post,
1010
Put,
11+
UseGuards,
1112
UseInterceptors,
1213
} from '@nestjs/common';
1314
import { plainToInstance } from 'class-transformer';
1415
import { BusinessErrorsInterceptor } from '../shared/interceptors/business-errors.interceptor';
1516
import { ReviewDto } from './review.dto';
1617
import { ReviewEntity } from './review.entity';
1718
import { ReviewService } from './review.service';
19+
import { HasRoles } from '../auth/has-roles.decorator';
20+
import { Role } from '../auth/role.enum';
21+
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
22+
import { RolesGuard } from 'src/auth/roles.guard';
1823

1924
@Controller('reviews')
2025
@UseInterceptors(BusinessErrorsInterceptor)
2126
export class ReviewController {
2227
constructor(private readonly reviewService: ReviewService) {}
2328

29+
@HasRoles(Role.AdminReview, Role.LecturaReview)
30+
@UseGuards(JwtAuthGuard, RolesGuard)
2431
@Get()
2532
async findAll() {
2633
return await this.reviewService.findAll();
2734
}
2835

36+
@HasRoles(Role.AdminReview, Role.LecturaReview)
37+
@UseGuards(JwtAuthGuard, RolesGuard)
2938
@Get(':reviewId')
3039
async findOne(@Param('reviewId') reviewId: string) {
3140
return await this.reviewService.findOne(reviewId);
3241
}
3342

43+
@HasRoles(Role.AdminReview, Role.EscrituraReview)
44+
@UseGuards(JwtAuthGuard, RolesGuard)
3445
@Post()
3546
async create(@Body() reviewDto: ReviewDto) {
3647
const review: ReviewEntity = plainToInstance(ReviewEntity, reviewDto);
3748
return await this.reviewService.create(review);
3849
}
3950

51+
@HasRoles(Role.AdminReview, Role.EscrituraReview)
52+
@UseGuards(JwtAuthGuard, RolesGuard)
4053
@Put(':reviewId')
4154
async update(
4255
@Param('reviewId') reviewId: string,
@@ -46,6 +59,8 @@ export class ReviewController {
4659
return await this.reviewService.update(reviewId, review);
4760
}
4861

62+
@HasRoles(Role.AdminReview, Role.EliminarReview)
63+
@UseGuards(JwtAuthGuard, RolesGuard)
4964
@Delete(':reviewId')
5065
@HttpCode(204)
5166
async delete(@Param('reviewId') reviewId: string) {

0 commit comments

Comments
 (0)