Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(csi-944): refactor code for maintainability #379

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ services:
volumes:
# override the default values with our own - this is because the KAFKA_HOST env variable is ignored for some reason
- ./docker/ml-api-adapter/default.json:/opt/app/config/default.json
# TODO: we should be able to remove this - I think the image command is broken
command:
- "node"
- "src/api/index.js"
Expand Down
2 changes: 0 additions & 2 deletions scripts/_wait4_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ async function updateServiceStatus (waitingMap) {
const startingServices = getServicesForStatus(waitingMap, 'starting')

Promise.all(startingServices.map(async serviceName => {
// TODO: This info may be useful in future!
// const currentStatus = waitingMap[serviceName]
const progress = await getProgress(serviceName)
waitingMap[serviceName] = progress
}))
Expand Down
12 changes: 6 additions & 6 deletions src/api/bulkQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ const { kafkaConfig } = new Config()
*/
module.exports = {
/**
* summary: BulkQuotes
* description: The HTTP request POST /bulkQuotes is used to request the creation of a bulk quote for the provided financial transactions in the server.
* parameters: body, Accept, Content-Length, Content-Type, Date, X-Forwarded-For, FSPIOP-Source, FSPIOP-Destination, FSPIOP-Encryption, FSPIOP-Signature, FSPIOP-URI, FSPIOP-HTTP-Method
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
* summary: BulkQuotes
* description: The HTTP request POST /bulkQuotes is used to request the creation of a bulk quote for the provided financial transactions in the server.
* parameters: body, Accept, Content-Length, Content-Type, Date, X-Forwarded-For, FSPIOP-Source, FSPIOP-Destination, FSPIOP-Encryption, FSPIOP-Signature, FSPIOP-URI, FSPIOP-HTTP-Method
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
post: async function BulkQuotes (context, request, h) {
const histTimerEnd = Metrics.getHistogram(
'bulkQuotes_post',
Expand Down
24 changes: 12 additions & 12 deletions src/api/bulkQuotes/{id}.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ const { kafkaConfig } = new Config()
*/
module.exports = {
/**
* summary: getBulkQuotesById
* description: The HTTP request GET /bulkQuotes/<id> is used to get information regarding an earlier created or requested bulk quote. The <id> in the URI should contain the bulkQuoteId that was used for the creation of the bulk quote.
* parameters: Accept
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
* summary: getBulkQuotesById
* description: The HTTP request GET /bulkQuotes/<id> is used to get information regarding an earlier created or requested bulk quote. The <id> in the URI should contain the bulkQuoteId that was used for the creation of the bulk quote.
* parameters: Accept
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
get: async function getBulkQuotesById (context, request, h) {
const histTimerEnd = Metrics.getHistogram(
'bulkQuotes_id_get',
Expand All @@ -75,12 +75,12 @@ module.exports = {
}
},
/**
* summary: putBulkQuotesById
* description: The callback PUT /bulkQuotes/<id> is used to inform the client of a requested or created bulk quote. The <id> in the URI should contain the bulkQuoteId that was used for the creation of the bulk quote, or the <id> that was used in the GET /bulkQuotes/<id>.
* parameters: body, Content-Length
* produces: application/json
* responses: 200, 400, 401, 403, 404, 405, 406, 501, 503
*/
* summary: putBulkQuotesById
* description: The callback PUT /bulkQuotes/<id> is used to inform the client of a requested or created bulk quote. The <id> in the URI should contain the bulkQuoteId that was used for the creation of the bulk quote, or the <id> that was used in the GET /bulkQuotes/<id>.
* parameters: body, Content-Length
* produces: application/json
* responses: 200, 400, 401, 403, 404, 405, 406, 501, 503
*/
put: async function putBulkQuotesById (context, request, h) {
const histTimerEnd = Metrics.getHistogram(
'bulkQuotes_id_put',
Expand Down
16 changes: 8 additions & 8 deletions src/api/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const { kafkaConfig } = new Config()
*/
module.exports = {
/**
* summary: Quotes
* description:
* - The HTTP request POST /quotes is used to request the creation of a quote for the provided financial transaction in the server.
* - The HTTP request `POST /fxQuotes` is used to ask an FXP to provide a quotation for a currency conversion.
* parameters: body, Accept, Content-Length, Content-Type, Date, X-Forwarded-For, FSPIOP-Source, FSPIOP-Destination, FSPIOP-Encryption, FSPIOP-Signature, FSPIOP-URI, FSPIOP-HTTP-Method
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
* summary: Quotes
* description:
* - The HTTP request POST /quotes is used to request the creation of a quote for the provided financial transaction in the server.
* - The HTTP request `POST /fxQuotes` is used to ask an FXP to provide a quotation for a currency conversion.
* parameters: body, Accept, Content-Length, Content-Type, Date, X-Forwarded-For, FSPIOP-Source, FSPIOP-Destination, FSPIOP-Encryption, FSPIOP-Signature, FSPIOP-URI, FSPIOP-HTTP-Method
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
post: async function Quotes (context, request, h) {
const isFX = !!request.payload.conversionRequestId

Expand Down
36 changes: 18 additions & 18 deletions src/api/quotes/{id}.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const { kafkaConfig } = new Config()
*/
module.exports = {
/**
* summary: QuotesById
* description:
* - The HTTP request GET /quotes/<id> is used to get information regarding an earlier created or requested quote. The <id> in the URI should contain the quoteId that was used for the creation of the quote.
* - The HTTP request `GET /fxQuotes/{ID}` is used to request information regarding a request for quotation for a currency conversion which the sender has previously issued. The `{ID}` in the URI should contain the `conversionRequestId` that was used for the creation of the quote.
* parameters: Accept
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
* summary: QuotesById
* description:
* - The HTTP request GET /quotes/<id> is used to get information regarding an earlier created or requested quote. The <id> in the URI should contain the quoteId that was used for the creation of the quote.
* - The HTTP request `GET /fxQuotes/{ID}` is used to request information regarding a request for quotation for a currency conversion which the sender has previously issued. The `{ID}` in the URI should contain the `conversionRequestId` that was used for the creation of the quote.
* parameters: Accept
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
*/
get: async function getQuotesById (context, request, h) {
const isFX = request.headers['content-type'].includes('fxQuotes')

Expand Down Expand Up @@ -84,16 +84,16 @@ module.exports = {
},

/**
* summary: QuotesById and QuotesByIdAndError
* description:
* - The callback PUT /quotes/<id> is used to inform the client of a requested or created quote. The <id> in the URI should contain the quoteId that was used for the creation of the quote, or the <id> that was used in the GET /quotes/<id>GET /quotes/<id>,
* - The callback `PUT /fxQuotes/{ID}` is used to inform the requester about the outcome of a request for quotation for a currency conversion. The `{ID}` in the URI should contain the `conversionRequestId` that was used for the creation of the FX quote, or the `{ID}` that was used in the `GET /fxQuotes/{ID}` request.
* - If the server is unable to find or create a quote, or some other processing error occurs, the error callback PUT /quotes/<id>/error is used. The <id> in the URI should contain the quoteId that was used for the creation of the quote, or the <id> that was used in the GET /quotes/<id>.
* - If the FXP is unable to find or create a FX quote, or some other processing error occurs, the error callback `PUT /fxQuotes/{ID}/error` is used. The `{ID}` in the URI should contain the `conversionRequestId` that was used for the creation of the FX quote, or the `{ID}` that was used in the `GET /fxQuotes/{ID}` request.
* parameters: body, Content-Length
* produces: application/json
* responses: 200, 400, 401, 403, 404, 405, 406, 501, 503
*/
* summary: QuotesById and QuotesByIdAndError
* description:
* - The callback PUT /quotes/<id> is used to inform the client of a requested or created quote. The <id> in the URI should contain the quoteId that was used for the creation of the quote, or the <id> that was used in the GET /quotes/<id>GET /quotes/<id>,
* - The callback `PUT /fxQuotes/{ID}` is used to inform the requester about the outcome of a request for quotation for a currency conversion. The `{ID}` in the URI should contain the `conversionRequestId` that was used for the creation of the FX quote, or the `{ID}` that was used in the `GET /fxQuotes/{ID}` request.
* - If the server is unable to find or create a quote, or some other processing error occurs, the error callback PUT /quotes/<id>/error is used. The <id> in the URI should contain the quoteId that was used for the creation of the quote, or the <id> that was used in the GET /quotes/<id>.
* - If the FXP is unable to find or create a FX quote, or some other processing error occurs, the error callback `PUT /fxQuotes/{ID}/error` is used. The `{ID}` in the URI should contain the `conversionRequestId` that was used for the creation of the FX quote, or the `{ID}` that was used in the `GET /fxQuotes/{ID}` request.
* parameters: body, Content-Length
* produces: application/json
* responses: 200, 400, 401, 403, 404, 405, 406, 501, 503
*/
put: async function putQuotesById (context, request, h) {
const isFX = request.headers['content-type'].includes('fxQuotes')
const isError = !!request.payload.errorInformation
Expand Down
1 change: 0 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const HEADERS = Object.freeze({
fspiopSignature: 'FSPIOP-Signature',
fspiopUri: 'FSPIOP-URI'
})
// todo: think, if it's better to use all headers keys in lowercase

const ERROR_MESSAGES = {
CALLBACK_UNSUCCESSFUL_HTTP_RESPONSE: 'Got non-success response sending error callback',
Expand Down
70 changes: 36 additions & 34 deletions src/data/bulkQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@
/* istanbul ignore file */

'use strict'

const Mockgen = require('../../test/util/mockgen.js')

/**
* Operations on /bulkQuotes
*/
module.exports = {
/**
* summary: BulkQuotes
* description: The HTTP request POST /bulkQuotes is used to request the creation of a bulk quote for the provided financial transactions in the server.
* parameters: body, Accept, Content-Length, Content-Type, Date, X-Forwarded-For, FSPIOP-Source, FSPIOP-Destination, FSPIOP-Encryption, FSPIOP-Signature, FSPIOP-URI, FSPIOP-HTTP-Method
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
* operationId: BulkQuotes
*/
* summary: BulkQuotes
* description: The HTTP request POST /bulkQuotes is used to request the creation of a bulk quote for the provided financial transactions in the server.
* parameters: body, Accept, Content-Length, Content-Type, Date, X-Forwarded-For, FSPIOP-Source, FSPIOP-Destination, FSPIOP-Encryption, FSPIOP-Signature, FSPIOP-URI, FSPIOP-HTTP-Method
* produces: application/json
* responses: 202, 400, 401, 403, 404, 405, 406, 501, 503
* operationId: BulkQuotes
*/
post: {
202: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -60,9 +62,9 @@ module.exports = {
},
400: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -71,9 +73,9 @@ module.exports = {
},
401: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -82,9 +84,9 @@ module.exports = {
},
403: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -93,9 +95,9 @@ module.exports = {
},
404: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -104,9 +106,9 @@ module.exports = {
},
405: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -115,9 +117,9 @@ module.exports = {
},
406: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -126,9 +128,9 @@ module.exports = {
},
501: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand All @@ -137,9 +139,9 @@ module.exports = {
},
503: function (req, res, callback) {
/**
* Using mock data generator module.
* Replace this by actual data for the api.
*/
* Using mock data generator module.
* Replace this by actual data for the api.
*/
Mockgen().responses({
path: '/bulkQuotes',
operation: 'post',
Expand Down
Loading
Loading