Skip to content

Commit

Permalink
Merge pull request #34 from mpaperno/mp/25_empty_choice_updt
Browse files Browse the repository at this point in the history
Allow empty arrays in choiceUpdate() and choiceUpdateSpecific(); Validate that non-empty ID and a proper array type is passed.
  • Loading branch information
mpaperno committed Aug 12, 2023
2 parents 1910070 + 4c0552d commit 9a4c415
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,27 @@ class TouchPortalClient extends EventEmitter {
}

choiceUpdate(id, value) {
if (value.length <= 0) {
this.logIt('ERROR', 'choiceUpdate: value is an empty array');
throw new Error('choiceUpdate: value is an empty array');
if (!id) {
this.logIt('ERROR', 'choiceUpdate: ID parameter is empty');
throw new Error('choiceUpdate: ID parameter is empty');
}
if (!Array.isArray(value)) {
this.logIt('ERROR', 'choiceUpdate : value parameter must be an array');
throw new Error( 'choiceUpdate: value parameter must be an array');
}
this.send({ type: 'choiceUpdate', id, value });
}

choiceUpdateSpecific(id, value, instanceId) {
if (value.length <= 0) {
this.logIt('ERROR', 'choiceUpdateSpecific : value does not contain data in an array format');
throw new Error(
'choiceUpdateSpecific: value does not contain data in an array format',
);
if (!id) {
this.logIt('ERROR', 'choiceUpdateSpecific: ID parameter is empty');
throw new Error('choiceUpdateSpecific: ID parameter is empty');
}
if (!Array.isArray(value)) {
this.logIt('ERROR', 'choiceUpdateSpecific : value parameter must be an array');
throw new Error('choiceUpdateSpecific: value parameter must be an array');
}
if (!instanceId || instanceId === '') {
if (!instanceId) {
this.logIt('ERROR', 'choiceUpdateSpecific : instanceId is not populated');
throw new Error('choiceUpdateSpecific: instanceId is not populated');
}
Expand Down

0 comments on commit 9a4c415

Please sign in to comment.