Transact-Stats Code
Brought to you by:
chrisdoctor
File | Date | Author | Commit |
---|---|---|---|
.serverless | 2021-12-12 |
![]() |
[ce964f] refactor reducer function, error response forma... |
controller.js | 2021-12-12 |
![]() |
[797119] Initial commit |
helpers.js | 2021-12-12 |
![]() |
[ce964f] refactor reducer function, error response forma... |
model.js | 2021-12-12 |
![]() |
[ce964f] refactor reducer function, error response forma... |
readme.md | 2021-12-13 |
![]() |
[b1aa41] readme update endpoints |
serverless.yml | 2021-12-12 |
![]() |
[797119] Initial commit |
transact-stats.js | 2021-12-12 |
![]() |
[ce964f] refactor reducer function, error response forma... |
REST API using Node.js raw and Serverless Framework - Performs the calculation of simple statistics on financial transaction data
POST /transact-stats
POST /transact-stats?merchantType=<string>
The API returns one object containing one or more child objects of merchant sales data. Structure below:
{
"Merchant(1) ID": {
"salesTotal": number, // The total sales value of merchant
"salesNet": number, // The net sales value of merchant
"numberOfSales": number, // Counter of sales transactions (credits)
"salesAverage": number // The average net transaction value of merchant
},
"Merchant(2) ID": {
"salesTotal": number,
"salesNet": number,
"numberOfSales": number,
"salesAverage": number
},
.
.
.
"Merchant (n) ID": {
"salesTotal": number,
"salesNet": number,
"numberOfSales": number,
"salesAverage": number
},
}
# Get statistics using all transactions in array
# Endpoint: /api/transactions
curl -XPOST -H "Content-type: application/json" -d '[
{
"transactionId": "1",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": 100
},
{
"transactionId": "2",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -10
},
{
"transactionId": "3",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -25
},
{
"transactionId": "1",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": 300
},
{
"transactionId": "2",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -30
},
{
"transactionId": "3",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -40
},
{
"transactionId": "1",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_2",
"merchantType": "TYPE_1",
"value": 500
},
{
"transactionId": "1",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_3",
"merchantType": "TYPE_2",
"value": 1000
},
{
"transactionId": "2",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_3",
"merchantType": "TYPE_2",
"value": -200
},
{
"transactionId": "1",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_3",
"merchantType": "TYPE_2",
"value": 400
}
]' 'https://kv583p4c30.execute-api.ap-southeast-1.amazonaws.com/dev/transact-stats'
# Get statistics only for transactions with merchantType = "TYPE_1"
# Endpoint: /api/transactions/TYPE_1
curl -XPOST -H "Content-type: application/json" -d '[
{
"transactionId": "1",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": 100
},
{
"transactionId": "2",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -10
},
{
"transactionId": "3",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -25
},
{
"transactionId": "1",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": 300
},
{
"transactionId": "2",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -30
},
{
"transactionId": "3",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_1",
"merchantType": "TYPE_1",
"value": -40
},
{
"transactionId": "1",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_2",
"merchantType": "TYPE_1",
"value": 500
},
{
"transactionId": "1",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_3",
"merchantType": "TYPE_2",
"value": 1000
},
{
"transactionId": "2",
"transactionGroupId": "GRP_1",
"merchantId": "MERCH_3",
"merchantType": "TYPE_2",
"value": -200
},
{
"transactionId": "1",
"transactionGroupId": "GRP_2",
"merchantId": "MERCH_3",
"merchantType": "TYPE_2",
"value": 400
}
]' 'https://kv583p4c30.execute-api.ap-southeast-1.amazonaws.com/dev/transact-stats?merchantType=TYPE_1'