Skip to content

Commit f430125

Browse files
committed
Make remove area clearer
1 parent 4e309df commit f430125

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/commands/area/remove-area.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,19 @@ const codec = t.strict({
1717
type RemoveArea = t.TypeOf<typeof codec>;
1818

1919
const process: Command<RemoveArea>['process'] = input => {
20-
if (input.events.length === 0) {
20+
if (
21+
input.events.length === 0 ||
22+
pipe(input.events, RA.some(isEventOfType('AreaRemoved')))
23+
) {
2124
return TE.left(
2225
failureWithStatus(
2326
'The requested area does not exist',
2427
StatusCodes.NOT_FOUND
2528
)()
2629
);
2730
}
28-
return pipe(
29-
pipe(
30-
input.events,
31-
RA.filter(isEventOfType('AreaRemoved')),
32-
RA.match(
33-
() => O.some(constructEvent('AreaRemoved')(input.command)),
34-
() => O.none
35-
)
36-
),
37-
O.match(
38-
() =>
39-
TE.left(
40-
failureWithStatus(
41-
'The requested area does not exist',
42-
StatusCodes.NOT_FOUND
43-
)()
44-
),
45-
event => TE.right(O.some(event))
46-
)
47-
);
31+
32+
return TE.right(O.some(constructEvent('AreaRemoved')(input.command)));
4833
};
4934

5035
const resource: Command<RemoveArea>['resource'] = command => ({

0 commit comments

Comments
 (0)