@@ -6,13 +6,15 @@ import {
66} from '../../types/failure-with-status' ;
77import * as TE from 'fp-ts/TaskEither' ;
88import * as E from 'fp-ts/Either' ;
9- import { EventsTable } from './events-table' ;
9+ import * as RA from 'fp-ts/ReadonlyArray' ;
10+ import { EventExclusionsTable , EventsTable } from './events-table' ;
1011import { eventsFromRows } from './events-from-rows' ;
1112import { Client } from '@libsql/client' ;
1213import { StatusCodes } from 'http-status-codes' ;
1314import { DomainEvent } from '../../types' ;
1415import { EventName , EventOfType } from '../../types/domain-event' ;
1516import { dbExecute } from '../../util' ;
17+ import { exclusionEventsFromRows } from './exclusion-events-from-rows' ;
1618
1719export const getAllEvents =
1820 ( dbClient : Client ) : Dependencies [ 'getAllEvents' ] =>
@@ -132,3 +134,32 @@ export const getAllEventsByTypes =
132134 ReadonlyArray < EventOfType < T > | EventOfType < R > >
133135 > ( es => es as ReadonlyArray < EventOfType < T > | EventOfType < R > > )
134136 ) ;
137+
138+ export const getAllExclusionEvents = ( dbClient : Client ) : Dependencies [ 'getAllExclusionEvents' ] =>
139+ ( ) =>
140+ pipe (
141+ TE . tryCatch (
142+ ( ) =>
143+ dbExecute (
144+ dbClient ,
145+ `
146+ SELECT events_exclusions.*, events.payload, events.event_type
147+ FROM events_exclusions
148+ INNER JOIN events ON events.id = events_exclusions.event_id
149+ ` ,
150+ { }
151+ ) ,
152+ failureWithStatus (
153+ 'Failed to query database' ,
154+ StatusCodes . INTERNAL_SERVER_ERROR
155+ )
156+ ) ,
157+ TE . chainEitherK (
158+ flow (
159+ EventExclusionsTable . decode ,
160+ E . mapLeft ( internalCodecFailure ( 'Failed to decode event exclusions DB table' ) )
161+ )
162+ ) ,
163+ TE . map ( table => table . rows ) ,
164+ TE . map ( exclusionEventsFromRows )
165+ ) ;
0 commit comments