File tree 3 files changed +25
-39
lines changed
domain/src/server/use-cases
resource/src/lib/controllers
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' ;
1
2
import { ApiProperty , ApiPropertyOptional } from '@nestjs/swagger' ;
2
3
import { EventFormat } from '@devmx/shared-api-interfaces' ;
4
+ import { UserRefDto } from '@devmx/shared-data-source' ;
3
5
import { CreateEvent } from '@devmx/event-domain' ;
6
+ import { Type } from 'class-transformer' ;
4
7
import {
5
8
IsBoolean ,
6
- IsDateString ,
9
+ IsDate ,
7
10
IsNotEmpty ,
8
11
IsOptional ,
9
12
IsString ,
@@ -31,16 +34,11 @@ export class CreateEventDto implements CreateEvent {
31
34
} )
32
35
format : EventFormat ;
33
36
34
- @IsDateString ( )
35
- @IsOptional ( )
36
- @ApiPropertyOptional ( )
37
+ @IsDate ( { message : 'Data inválida' } )
38
+ @ApiProperty ( )
39
+ @Type ( ( ) => Date )
37
40
date : Date ;
38
41
39
- // @IsString ()
40
- // @IsOptional ()
41
- // @ApiPropertyOptional ()
42
- // time: string;
43
-
44
42
@IsString ( )
45
43
@IsOptional ( )
46
44
@ApiPropertyOptional ( )
@@ -51,14 +49,18 @@ export class CreateEventDto implements CreateEvent {
51
49
@ApiPropertyOptional ( )
52
50
visible = false ;
53
51
52
+ @ApiProperty ( { type : ( ) => [ PresentationRefDto ] } )
53
+ @Type ( ( ) => PresentationRefDto )
54
+ presentations : PresentationRefDto [ ] ;
55
+
56
+ @ApiProperty ( { type : ( ) => [ UserRefDto ] } )
57
+ @Type ( ( ) => UserRefDto )
58
+ leaders : UserRefDto [ ] ;
59
+
54
60
@IsString ( )
55
61
@IsOptional ( )
56
62
@ApiPropertyOptional ( )
57
63
address : string ;
58
64
59
- // city?: string;
60
-
61
- // location?: string;
62
-
63
65
owner : string ;
64
66
}
Original file line number Diff line number Diff line change 1
- import { NotFoundError , PersistenceError } from '@devmx/shared-util-errors' ;
2
1
import { createUseCaseProvider } from '@devmx/shared-util-data/server' ;
3
2
import { Event , UseCase } from '@devmx/shared-api-interfaces' ;
4
3
import { EventsService } from '../services' ;
@@ -8,21 +7,7 @@ export class UpdateEventUseCase implements UseCase<UpdateEvent, Event> {
8
7
constructor ( private eventsService : EventsService ) { }
9
8
10
9
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 ) ;
26
11
}
27
12
}
28
13
Original file line number Diff line number Diff line change @@ -11,14 +11,14 @@ import {
11
11
} from '@devmx/shared-data-source' ;
12
12
import {
13
13
Get ,
14
+ Res ,
14
15
Post ,
15
16
Body ,
16
17
Param ,
17
18
Patch ,
18
19
Query ,
19
20
Delete ,
20
21
Controller ,
21
- Res ,
22
22
BadRequestException ,
23
23
ForbiddenException ,
24
24
NotFoundException ,
@@ -204,25 +204,24 @@ export class EventsController {
204
204
async update (
205
205
@User ( ) auth : AuthUser ,
206
206
@Param ( 'id' ) id : string ,
207
- @Body ( ) updateEventDto : UpdateEventDto
207
+ @Body ( ) data : UpdateEventDto
208
208
) {
209
209
const event = await this . eventsFacade . findOne ( id ) ;
210
210
211
211
if ( ! event ) {
212
- throw exceptionByError ( {
213
- code : 404 ,
214
- message : 'Evento não encontrado' ,
215
- } ) ;
212
+ throw new NotFoundException ( 'Evento não encontrado' ) ;
216
213
}
217
214
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' ) ;
220
219
}
221
220
222
221
try {
223
- return await this . eventsFacade . update ( id , updateEventDto ) ;
222
+ return await this . eventsFacade . update ( id , { ... data , owner : auth . id } ) ;
224
223
} catch ( err ) {
225
- throw exceptionByError ( { code : 400 , message : 'Solicitação incorreta' } ) ;
224
+ throw new BadRequestException ( err ) ;
226
225
}
227
226
}
228
227
You can’t perform that action at this time.
0 commit comments