File tree Expand file tree Collapse file tree 3 files changed +25
-39
lines changed
domain/src/server/use-cases
resource/src/lib/controllers Expand file tree Collapse file tree 3 files changed +25
-39
lines changed Original file line number Diff line number Diff line change 1+ import { PresentationRefDto } from '@devmx/presentation-data-source' ;
12import { ApiProperty , ApiPropertyOptional } from '@nestjs/swagger' ;
23import { EventFormat } from '@devmx/shared-api-interfaces' ;
4+ import { UserRefDto } from '@devmx/shared-data-source' ;
35import { CreateEvent } from '@devmx/event-domain' ;
6+ import { Type } from 'class-transformer' ;
47import {
58 IsBoolean ,
6- IsDateString ,
9+ IsDate ,
710 IsNotEmpty ,
811 IsOptional ,
912 IsString ,
@@ -31,16 +34,11 @@ export class CreateEventDto implements CreateEvent {
3134 } )
3235 format : EventFormat ;
3336
34- @IsDateString ( )
35- @IsOptional ( )
36- @ApiPropertyOptional ( )
37+ @IsDate ( { message : 'Data inválida' } )
38+ @ApiProperty ( )
39+ @Type ( ( ) => Date )
3740 date : Date ;
3841
39- // @IsString ()
40- // @IsOptional ()
41- // @ApiPropertyOptional ()
42- // time: string;
43-
4442 @IsString ( )
4543 @IsOptional ( )
4644 @ApiPropertyOptional ( )
@@ -51,14 +49,18 @@ export class CreateEventDto implements CreateEvent {
5149 @ApiPropertyOptional ( )
5250 visible = false ;
5351
52+ @ApiProperty ( { type : ( ) => [ PresentationRefDto ] } )
53+ @Type ( ( ) => PresentationRefDto )
54+ presentations : PresentationRefDto [ ] ;
55+
56+ @ApiProperty ( { type : ( ) => [ UserRefDto ] } )
57+ @Type ( ( ) => UserRefDto )
58+ leaders : UserRefDto [ ] ;
59+
5460 @IsString ( )
5561 @IsOptional ( )
5662 @ApiPropertyOptional ( )
5763 address : string ;
5864
59- // city?: string;
60-
61- // location?: string;
62-
6365 owner : string ;
6466}
Original file line number Diff line number Diff line change 1- import { NotFoundError , PersistenceError } from '@devmx/shared-util-errors' ;
21import { createUseCaseProvider } from '@devmx/shared-util-data/server' ;
32import { Event , UseCase } from '@devmx/shared-api-interfaces' ;
43import { EventsService } from '../services' ;
@@ -8,21 +7,7 @@ export class UpdateEventUseCase implements UseCase<UpdateEvent, Event> {
87 constructor ( private eventsService : EventsService ) { }
98
109 async execute ( data : UpdateEvent ) {
11- const event = await this . eventsService . findOne ( data . id ) ;
12-
13- if ( ! event ) {
14- throw new NotFoundError ( `Evento não encontrado` ) ;
15- }
16-
17- const updated = await this . eventsService . update ( data . id , data ) ;
18-
19- if ( ! updated ) {
20- throw new PersistenceError (
21- `Algo deu errado ao persistir os dados do evento`
22- ) ;
23- }
24-
25- return updated ;
10+ return await this . eventsService . update ( data . id , data ) ;
2611 }
2712}
2813
Original file line number Diff line number Diff line change @@ -11,14 +11,14 @@ import {
1111} from '@devmx/shared-data-source' ;
1212import {
1313 Get ,
14+ Res ,
1415 Post ,
1516 Body ,
1617 Param ,
1718 Patch ,
1819 Query ,
1920 Delete ,
2021 Controller ,
21- Res ,
2222 BadRequestException ,
2323 ForbiddenException ,
2424 NotFoundException ,
@@ -204,25 +204,24 @@ export class EventsController {
204204 async update (
205205 @User ( ) auth : AuthUser ,
206206 @Param ( 'id' ) id : string ,
207- @Body ( ) updateEventDto : UpdateEventDto
207+ @Body ( ) data : UpdateEventDto
208208 ) {
209209 const event = await this . eventsFacade . findOne ( id ) ;
210210
211211 if ( ! event ) {
212- throw exceptionByError ( {
213- code : 404 ,
214- message : 'Evento não encontrado' ,
215- } ) ;
212+ throw new NotFoundException ( 'Evento não encontrado' ) ;
216213 }
217214
218- if ( event . owner . id !== auth . id && ! authIsAdmin ( auth . roles ) ) {
219- throw exceptionByError ( { code : 403 , message : 'Acesso negado' } ) ;
215+ const isLeader = event . leaders . some ( ( leader ) => leader . id === auth . id ) ;
216+
217+ if ( ! isLeader && ! authIsAdmin ( auth . roles ) ) {
218+ throw new ForbiddenException ( 'Acesso negado' ) ;
220219 }
221220
222221 try {
223- return await this . eventsFacade . update ( id , updateEventDto ) ;
222+ return await this . eventsFacade . update ( id , { ... data , owner : auth . id } ) ;
224223 } catch ( err ) {
225- throw exceptionByError ( { code : 400 , message : 'Solicitação incorreta' } ) ;
224+ throw new BadRequestException ( err ) ;
226225 }
227226 }
228227
You can’t perform that action at this time.
0 commit comments