Skip to content

Commit

Permalink
in updateParentUuid,
Browse files Browse the repository at this point in the history
* include 'PARENT_UUID' in the queried fields
* if PARENT_UUID is already set, then emit an error

addresses #9

Needs to be tested on the live airtable

Question--
Does req.emit('error') prevent the rest of the airtable update from 
continuing?
  • Loading branch information
dorey committed Oct 22, 2020
1 parent c7c1b4f commit 17a51cf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion updateParentUuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function writeNewUuid(airtableRecordId, newUuid) {

function updateParentUuid(participantId, newUuid) {
const queryUrl = new URL(airtableBaseUrl);
queryUrl.searchParams.set('fields[]', AT.ID_OF_PARTICIPANT);
queryUrl.searchParams.append('fields[]', `${AT.PARENT_UUID}`);
queryUrl.searchParams.append('fields[]', `${AT.ID_OF_PARTICIPANT}`);
queryUrl.searchParams.set('filterByFormula', `{${AT.ID_OF_PARTICIPANT}} = ${participantId}`);
const req = https.request(queryUrl, {method: 'GET', headers: airtableHeaders}, (res) => {
res.on('data', (d) => {
Expand All @@ -69,6 +70,15 @@ function updateParentUuid(participantId, newUuid) {
);
return;
}

if (records[0][AT.PARENT_UUID]) {
req.emit(
'error',
`Participant link used multiple times`
);
return;
}

writeNewUuid(records[0].id, newUuid);
});
});
Expand Down

0 comments on commit 17a51cf

Please sign in to comment.