Skip to content

Commit

Permalink
commits rolled back and new pr created to align response objects with…
Browse files Browse the repository at this point in the history
… swagger (#18)
  • Loading branch information
rmothilal authored May 20, 2019
1 parent 7f6274b commit 3242b84
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/oracle/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ exports.createParticipantsByTypeAndId = function (request, h) {
partyList: [
{
fspId: request.payload.fspId,
currency: request.payload.currency,
partySubIdOrType: request.payload.partySubIdOrType
currency: request.payload.currency || undefined,
partySubIdOrType: request.payload.partySubIdOrType || undefined
}
]
}
Expand Down Expand Up @@ -129,7 +129,7 @@ exports.delParticipantsByTypeId = function (request, h) {
'Histogram for Simulator http operations',
['success', 'operation', 'source', 'destination']
).startTimer()
Logger.debug(`deleteParticipantsByTypeId::ID=${request.params.ID}`)
Logger.debug(`delParticipantsByTypeId::ID=${request.params.ID}`)
addNewRequest(request)
let idMap
if (participantsCache.get(request.params.Type)) {
Expand Down Expand Up @@ -158,7 +158,9 @@ exports.createParticipantsBatch = function (request, h) {
'Histogram for Simulator http operations',
['success', 'operation', 'source', 'destination']
).startTimer()
let failedList = []
let responseObject = {
partyList: []
}
if (batchRequestCache.get(request.payload.requestId)) {
let errorObject = {
errorCode: 2345,
Expand All @@ -184,6 +186,14 @@ exports.createParticipantsBatch = function (request, h) {
}
]
}
let partyId = {
partyIdType: party.partyIdType,
partyIdentifier: party.partyIdentifier,
partySubIdOrType: party.partySubIdOrType || undefined,
fspId: party.fspId,
currency: party.currency || undefined
}
let errorInformation
let idMap = new Map()
if (participantsCache.get(party.partyIdType)) {
idMap = participantsCache.get(party.partyIdType)
Expand All @@ -192,20 +202,22 @@ exports.createParticipantsBatch = function (request, h) {
errorCode: 1234,
errorDescription: `Participant:${party.partyIdentifier} already exists`
}
histTimerEnd({ success: false, operation: 'postParticipantsBatch', source: request.headers['fspiop-source'], destination: request.headers['fspiop-destination'] })
failedList.push(buildErrorObject(errorObject, []))
errorInformation = buildErrorObject(errorObject, [{ key: party.partyIdentifier, value: party.partyIdType }])
responseObject.partyList.push({ partyId, errorInformation })
} else {
idMap.set(party.partyIdentifier, record)
participantsCache.set(party.partyIdType, idMap)
responseObject.partyList.push({ partyId })
}
} else {
idMap.set(party.partyIdentifier, record)
participantsCache.set(party.partyIdType, idMap)
responseObject.partyList.push({ partyId })
}
}
}
histTimerEnd({ success: true, operation: 'postParticipantsBatch', source: request.headers['fspiop-source'], destination: request.headers['fspiop-destination'] })
return h.response(failedList.length > 0 ? failedList : null).code(201)
return h.response(responseObject).code(201)
}

exports.getRequestByTypeId = function (request, h) {
Expand Down Expand Up @@ -265,10 +277,8 @@ const addNewRequest = function (request) {

const buildErrorObject = function (error, extensionList) {
return {
errorInformation: {
errorCode: error.errorCode.toString(),
errorDescription: error.errorDescription,
extensionList
}
errorCode: error.errorCode.toString(),
errorDescription: error.errorDescription,
extensionList
}
}

0 comments on commit 3242b84

Please sign in to comment.