-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Listening to transaction event only now
- Loading branch information
Showing
9 changed files
with
61 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export enum TransactionType { | ||
INBOUND = 'INBOUND', | ||
OUTBOUND = 'OUTBOUND' | ||
} | ||
|
||
export interface TransactionEvent { | ||
accountId: string; | ||
currency: string; | ||
amount: number; | ||
type: TransactionType; | ||
transactionId: string; | ||
date: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
import { Statement } from '../models/statement' | ||
import { connectToDatabase } from '../utils/connectToDB' | ||
import { ReportingService } from '../services/reportingService' | ||
import { AccountEvent, Events, TransactionEvent } from '../events/events' | ||
import { TransactionEvent } from '../events/transactionEvent' | ||
|
||
interface EventBridgeEvent { | ||
'detail-type': Events | ||
detail: AccountEvent | TransactionEvent | ||
detail: TransactionEvent | ||
} | ||
|
||
export const handler = async (event: EventBridgeEvent): Promise<void> => { | ||
await connectToDatabase() | ||
const reportingService = new ReportingService(Statement) | ||
const eventBridgeEvent = JSON.stringify(event, null, 2) | ||
const eventDetails = JSON.parse(eventBridgeEvent)['detail'] | ||
console.log({eventDetails}) | ||
|
||
try { | ||
if (event['detail-type'] === Events.TransactionCreated) { | ||
await reportingService.processTransactionEvent(eventDetails) | ||
} else if ([Events.AccountCreated, Events.AccountUpdated].includes(event['detail-type'])) { | ||
await reportingService.processAccountEvent(eventDetails) | ||
} | ||
await reportingService.processTransactionEvent(eventDetails) | ||
} catch (e) { | ||
console.error("Error in processing event", e) | ||
console.error('Error in processing event', e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters