File tree Expand file tree Collapse file tree 4 files changed +26
-5
lines changed
init-dependencies/event-store Expand file tree Collapse file tree 4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 11import { Type } from 'io-ts' ;
22import { DomainEvent } from '../types/domain-event' ;
33import * as O from 'fp-ts/Option' ;
4+ import * as TE from 'fp-ts/TaskEither' ;
45import { Actor } from '../types/actor' ;
56import { Resource } from '../types/resource' ;
7+ import { FailureWithStatus } from '../types/failure-with-status' ;
8+ import { Dependencies } from '../dependencies' ;
69
710export type WithActor < T > = T & { actor : Actor } ;
811
@@ -11,7 +14,8 @@ export type Command<T> = {
1114 process : ( input : {
1215 command : WithActor < T > ;
1316 events : ReadonlyArray < DomainEvent > ;
14- } ) => O . Option < DomainEvent > ;
17+ deps : Dependencies ;
18+ } ) => TE . TaskEither < FailureWithStatus , O . Option < DomainEvent > > ;
1519 decode : Type < T , T , unknown > [ 'decode' ] ;
1620 isAuthorized : ( input : {
1721 actor : Actor ;
Original file line number Diff line number Diff line change @@ -21,11 +21,13 @@ const renderForm = (viewModel: ViewModel) =>
2121 pipe (
2222 html `
2323 < h1 > Exclude an event</ h1 >
24- < p > Are you sure you want to exclude (delete) this event? This form should only be used
24+ < p > Are you sure you want to exclude (delete) this event? This form should only be used in limited circumstances.
2525 </ p >
2626 ${ renderEvent ( viewModel . event . value ) }
2727 < form action ="/events/exclude-event " method ="post ">
2828 < input type ="hidden " name ="event_id " value ="${ viewModel . event . value . event_id } "/>
29+ < label for ="reason "> Whats the reason for deleting this event?</ label >
30+ < input type ="text " name ="reason " id ="reason " value ="" minlength ="3 " required />
2931 < button type ="submit "> Confirm</ button >
3032 </ form >
3133 ` ,
Original file line number Diff line number Diff line change 11import * as t from 'io-ts' ;
22import * as tt from 'io-ts-types' ;
33import * as O from 'fp-ts/Option' ;
4+ import * as TE from 'fp-ts/TaskEither' ;
45import { Command } from '../command' ;
56import { isAdminOrSuperUser } from '../is-admin-or-super-user' ;
7+ import { pipe } from 'fp-ts/lib/function' ;
8+ import { FailureWithStatus , failureWithStatus } from '../../types/failure-with-status' ;
9+ import { StatusCodes } from 'http-status-codes' ;
610
711const codec = t . strict ( {
8- event_id : tt . UUID
12+ event_id : tt . UUID ,
13+ reason : t . string ,
914} ) ;
1015
1116export type ExcludeEvent = t . TypeOf < typeof codec > ;
1217
13- const process : Command < ExcludeEvent > [ 'process' ] = ( ) => O . none ;
18+ const process : Command < ExcludeEvent > [ 'process' ] = input => pipe (
19+ input . command . actor . tag === 'user'
20+ ? TE . right < FailureWithStatus , number > ( input . command . actor . user . memberNumber )
21+ : TE . left ( failureWithStatus ( 'Unknown user' , StatusCodes . BAD_REQUEST ) ( ) ) ,
22+ TE . chain ( memberNumber => input . deps . excludeEvent (
23+ input . command . event_id ,
24+ memberNumber ,
25+ input . command . reason ,
26+ ) ) ,
27+ TE . map ( ( ) => O . none )
28+ ) ;
1429
1530const resource = ( ) => ( {
1631 type : 'ExcludeEvent' ,
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ export const excludeEvent =
4040 ]
4141 ) ,
4242 failureWithStatus (
43- 'Failed to execlude event' ,
43+ 'Failed to exclude event' ,
4444 StatusCodes . INTERNAL_SERVER_ERROR
4545 )
4646 ) ;
You can’t perform that action at this time.
0 commit comments