-
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.
- Loading branch information
Showing
5 changed files
with
71 additions
and
28 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 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,18 @@ | ||
{ | ||
"version": "0", | ||
"id": "c0cfc740-a244-f569-5a34-e7784dc1f12c", | ||
"detail-type": "TransactionCreated", | ||
"source": "accounts-service", | ||
"accountId": "123456789012", | ||
"time": "2024-08-29T07:35:00Z", | ||
"date": "2024-08-29T07:35:00Z", | ||
"region": "eu-north-1", | ||
"resources": [], | ||
"detail": { | ||
"accountId": "66cbccb349f8791ba0cc98b8", | ||
"type": "INBOUND", | ||
"currency": "USD", | ||
"amount": 909, | ||
"date": "2024-08-29T07:35:00Z" | ||
} | ||
} |
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,23 +1,21 @@ | ||
import { Statement } from '../models/statement' | ||
import { connectToDatabase } from '../utils/connectToDB' | ||
import { TransactionEvent } from '../events/transactionEvent' | ||
import { ReportingService } from '../services/reportingService' | ||
|
||
interface EventBridgeEvent { | ||
Records: { | ||
body: string; | ||
}[]; | ||
body: string | ||
} | ||
} | ||
|
||
export const handler = async (event: EventBridgeEvent): Promise<void> => { | ||
await connectToDatabase() | ||
const reportingService = new ReportingService(Statement) | ||
// Check if running locally by detecting if it's an API Gateway event or a direct invocation | ||
const records = event.Records | ||
console.log({ records }); | ||
for (const record of records) { | ||
const transactionEvent: TransactionEvent = JSON.parse(record.body) | ||
|
||
await reportingService.processTransactionEvent(transactionEvent) | ||
const transactionEvent = JSON.stringify(event, null, 2) | ||
|
||
try { | ||
await reportingService.processTransactionEvent(JSON.parse(transactionEvent).detail) | ||
} catch (e) { | ||
console.error("Error in processing transaction", 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