-
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.
feature #4 - add function, event adapters and class validator
- Loading branch information
1 parent
d9d96b8
commit fa76bc8
Showing
6 changed files
with
71 additions
and
0 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
import { ALBEvent } from 'aws-lambda' | ||
import { GetExchangeRateController } from '../../../3-adapters/controller/exchangeRate/getExchangeRateController' | ||
import { InputGetExchangeRate } from '../../../3-adapters/serializers/exchangeRate/getExchangeRate/input' | ||
import { ExchangeRateRepository } from '../../repositories/exchangeRateRepository' | ||
import { albHttpEventNormalizer } from '../../utility/eventAdapters' | ||
|
||
function eventAdapter (event: ALBEvent): InputGetExchangeRate { | ||
const body = albHttpEventNormalizer(event) | ||
return new InputGetExchangeRate(body) | ||
|
||
} | ||
|
||
exports.handler = async (event: ALBEvent) => { | ||
const getExchangeRateController = new GetExchangeRateController( | ||
new ExchangeRateRepository() | ||
) | ||
|
||
const input = eventAdapter(event) | ||
|
||
const response = await getExchangeRateController.run(input) | ||
|
||
return response | ||
} |
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,11 +1,16 @@ | ||
import { ExchangeRate } from '../../1-domain/entities/exchangeRate' | ||
import { ExchangeRateModel } from '../models/dynamo/exchangeRate' | ||
import { IExchangeRateRepository } from '../../2-business/repositories/iExchangeRateRepository' | ||
import { CurrencyEnum } from '../../2-business/enums/currencyEnum' | ||
|
||
export class ExchangeRateRepository implements IExchangeRateRepository { | ||
upsert (entity: ExchangeRate): Promise<ExchangeRate> { | ||
return ExchangeRateModel.create(entity, { | ||
overwrite: true | ||
}) | ||
} | ||
|
||
get (baseCurrency: CurrencyEnum): Promise<ExchangeRate> { | ||
return ExchangeRateModel.get({ baseCurrency }) | ||
} | ||
} |
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,11 @@ | ||
import { validateSync } from 'class-validator' | ||
|
||
export class InputClassValidator { | ||
errors () { | ||
const validationErrors = validateSync(this) | ||
return validationErrors.map((e) => ({ | ||
property: e.property, | ||
constraints: e.constraints | ||
})) | ||
} | ||
} |
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,15 @@ | ||
import { ALBEvent } from 'aws-lambda' | ||
|
||
export const albHttpEventNormalizer = (event: ALBEvent) => { | ||
let payload = {} | ||
if (event.queryStringParameters) { | ||
payload = { ...event.queryStringParameters } | ||
} | ||
|
||
if (event.body) { | ||
const body = JSON.parse(event.body) | ||
payload = { ...payload, ...body } | ||
} | ||
|
||
return payload | ||
} |