@@ -2,11 +2,14 @@ import {DomainEvent, constructEvent} from '../../types';
22import * as t from 'io-ts' ;
33import * as tt from 'io-ts-types' ;
44import * as O from 'fp-ts/Option' ;
5+ import * as TE from 'fp-ts/TaskEither' ;
56import { Command , WithActor } from '../command' ;
67import { isAdminOrSuperUser } from '../is-admin-or-super-user' ;
78import { isEquipmentTrainer } from '../is-equipment-trainer' ;
89import { Actor } from '../../types/actor' ;
910import { DateTime } from 'luxon' ;
11+ import { FailureWithStatus , failureWithStatus } from '../../types/failure-with-status' ;
12+ import { StatusCodes } from 'http-status-codes' ;
1013
1114const codec = t . strict ( {
1215 equipmentId : tt . UUID ,
@@ -20,18 +23,20 @@ export type MarkMemberTrainedBy = t.TypeOf<typeof codec>;
2023const process = ( input : {
2124 command : WithActor < MarkMemberTrainedBy > ;
2225 events : ReadonlyArray < DomainEvent > ;
23- } ) : O . Option < DomainEvent > =>
26+ } ) =>
2427 input . command . actor . tag !== 'user'
25- ? O . none
26- : O . some (
27- constructEvent ( 'MemberTrainedOnEquipmentBy' ) ( {
28- equipmentId : input . command . equipmentId ,
29- trainedByMemberNumber : input . command . trainedByMemberNumber ,
30- trainedAt : input . command . trainedAt ,
31- memberNumber : input . command . memberNumber ,
32- markedTrainedBy : input . command . actor . user . memberNumber ,
33- actor : input . command . actor ,
34- } )
28+ ? TE . left ( failureWithStatus ( 'Invalid Request' , StatusCodes . BAD_REQUEST ) ( ) )
29+ : TE . right (
30+ O . some (
31+ constructEvent ( 'MemberTrainedOnEquipmentBy' ) ( {
32+ equipmentId : input . command . equipmentId ,
33+ trainedByMemberNumber : input . command . trainedByMemberNumber ,
34+ trainedAt : input . command . trainedAt ,
35+ memberNumber : input . command . memberNumber ,
36+ markedTrainedBy : input . command . actor . user . memberNumber ,
37+ actor : input . command . actor ,
38+ } )
39+ )
3540 ) ;
3641
3742const resource = ( command : MarkMemberTrainedBy ) => ( {
0 commit comments