Skip to content

Commit

Permalink
feat(Validation): survey validation of fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rowasc committed Dec 4, 2020
1 parent a35be4b commit 5fc4689
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ushahidi-platform-sdk",
"version": "v0.3.2",
"version": "v0.3.3",
"description": "An SDK for the Ushahidi Platform - V3+ compatible",
"engines": {
"node": ">= 10 <13"
Expand Down
14 changes: 11 additions & 3 deletions src/surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ export class Surveys {
this.backendUrl = backendUrl;
this.setToken(token, expires);
}
static validateUniqueOptions(options: []) {

static fieldHasTranslations = (field, lang) => {
return field.translations[lang] && field.translations[lang].options.length > 0;
}

static fieldCanHaveOptions = (field) => {
return field.input === 'checkbox' || field.input === 'radio';
}

static areOptionsUnique(options: []) {
// converting to Set would remove duplicates,so if size matches original we are good
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
return new Set(options).size === options.length;
}
static validateNonEmptyOptions(options: []) {
static hasEmptyOptions(options: []) {
// check against duplicate or empty options
return options.filter(i => i === '' || i === null).length === 0;
return options.filter(i => i === '' || i === null).length > 0;
}

setToken(token?: string, expires?: number): object {
Expand Down

0 comments on commit 5fc4689

Please sign in to comment.