Skip to content

Commit

Permalink
Add Concepts#update to rename concepts (#112)
Browse files Browse the repository at this point in the history
Add Concepts#update to patch concept names
  • Loading branch information
eddiezane authored Nov 15, 2017
1 parent c3b712d commit 5c96620
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
13 changes: 13 additions & 0 deletions spec/concepts-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ describe('Concepts', () => {
})
.catch(errorHandler.bind(done));
});

it('updates a concept name', done => {
const originalName = conceptsIds[0];
const newName = `${originalName}-newName`;

app.concepts.update({ id: originalName, name: newName })
.then(concepts => {
expect(concepts[0].id).toBe(originalName);
expect(concepts[0].name).toBe(newName);
done();
})
.catch(errorHandler.bind(done));
});
});
35 changes: 33 additions & 2 deletions src/Concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,38 @@ class Concepts {
});
});
}
}
;

/**
* Update a concepts
* @param {object|object[]} concepts Can be a single concept object or an array of concept objects
* @param {object} concepts[].concept A concept object with the following attributes
* @param {object} concepts[].concept.id The concept's id (Required)
* @param {object} concepts[].concept.name The concept's new name
* @param {string} [action=overwrite] The action to use for the PATCH
* @return {Promise(Concepts, error)} A Promise that is fulfilled with a Concepts instance or rejected with an error
*/
update(concepts = [], action = 'overwrite') {
if (!checkType(/Array/, concepts)) {
concepts = [concepts];
}
const data = {
concepts,
action
};
const url = `${this._config.basePath}${CONCEPTS_PATH}`;
return wrapToken(this._config, headers => {
return new Promise((resolve, reject) => {
axios.patch(url, data, { headers })
.then((response) => {
if (isSuccess(response)) {
resolve(new Concepts(this._config, response.data.concepts));
} else {
reject(response);
}
}, reject);
});
});
}
};

module.exports = Concepts;

0 comments on commit 5c96620

Please sign in to comment.