|
|
@@ -182,32 +182,23 @@ async function updateOptType(
|
|
|
const requestVenId = oadrCreatedEvent.venId;
|
|
|
validateVenId(requestVenId, clientCertificateFingerprint, true);
|
|
|
|
|
|
- if (requestVenId !== clientCertificateFingerprint) {
|
|
|
- // as per certification item #512, venId MUST be case-sensitive
|
|
|
- const error = new Error('VenID does not match certificate');
|
|
|
- error.responseCode = 452;
|
|
|
- throw error;
|
|
|
- }
|
|
|
-
|
|
|
- const nantumRegistration = await nantum.fetchRegistration(requestVenId);
|
|
|
-
|
|
|
- const opted = nantumRegistration.opted || [];
|
|
|
+ let opted = await nantum.fetchOpted(requestVenId);
|
|
|
|
|
|
//TODO: more validation: VEN may opt into an event that doesn't exist. VEN may opt into an old version of an event
|
|
|
// (modificationNumber doesn't match). May opt into a completed event. Indicate error(s) to client.
|
|
|
|
|
|
for (const eventResponse of oadrCreatedEvent.eventResponses) {
|
|
|
// remove existing opts for this eventId
|
|
|
- nantumRegistration.opted = [
|
|
|
+ opted = [
|
|
|
...opted.filter(optedItem => optedItem.eventId !== eventResponse.eventId),
|
|
|
];
|
|
|
- nantumRegistration.opted.push({
|
|
|
+ opted.push({
|
|
|
eventId: eventResponse.eventId,
|
|
|
modificationNumber: eventResponse.modificationNumber,
|
|
|
optType: eventResponse.optType,
|
|
|
});
|
|
|
- await nantum.updateRegistration(nantumRegistration);
|
|
|
}
|
|
|
+ await nantum.updateOpted(requestVenId, opted);
|
|
|
|
|
|
return {
|
|
|
responseCode: '200',
|
|
|
@@ -217,8 +208,7 @@ async function updateOptType(
|
|
|
}
|
|
|
|
|
|
async function filterOutAcknowledgedEvents(venId, events) {
|
|
|
- const nantumRegistration = await nantum.fetchRegistration(venId);
|
|
|
- const opted = nantumRegistration.opted || [];
|
|
|
+ const opted = (await nantum.fetchOpted(venId)) || [];
|
|
|
return events.filter(
|
|
|
event =>
|
|
|
opted.filter(
|
|
|
@@ -264,7 +254,7 @@ async function pollForEvents(
|
|
|
return undefined;
|
|
|
}
|
|
|
|
|
|
-function validateVenId(requestVenId, clientCertificateFingerprint, required) {
|
|
|
+function validateVenId(requestVenId, clientCertificateFingerprint, required) {
|
|
|
if (requestVenId === clientCertificateFingerprint) {
|
|
|
return;
|
|
|
}
|