Skip to content

Commit 5c96620

Browse files
authored
Add Concepts#update to rename concepts (#112)
Add Concepts#update to patch concept names
1 parent c3b712d commit 5c96620

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

spec/concepts-spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,17 @@ describe('Concepts', () => {
6868
})
6969
.catch(errorHandler.bind(done));
7070
});
71+
72+
it('updates a concept name', done => {
73+
const originalName = conceptsIds[0];
74+
const newName = `${originalName}-newName`;
75+
76+
app.concepts.update({ id: originalName, name: newName })
77+
.then(concepts => {
78+
expect(concepts[0].id).toBe(originalName);
79+
expect(concepts[0].name).toBe(newName);
80+
done();
81+
})
82+
.catch(errorHandler.bind(done));
83+
});
7184
});

src/Concepts.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,38 @@ class Concepts {
119119
});
120120
});
121121
}
122-
}
123-
;
122+
123+
/**
124+
* Update a concepts
125+
* @param {object|object[]} concepts Can be a single concept object or an array of concept objects
126+
* @param {object} concepts[].concept A concept object with the following attributes
127+
* @param {object} concepts[].concept.id The concept's id (Required)
128+
* @param {object} concepts[].concept.name The concept's new name
129+
* @param {string} [action=overwrite] The action to use for the PATCH
130+
* @return {Promise(Concepts, error)} A Promise that is fulfilled with a Concepts instance or rejected with an error
131+
*/
132+
update(concepts = [], action = 'overwrite') {
133+
if (!checkType(/Array/, concepts)) {
134+
concepts = [concepts];
135+
}
136+
const data = {
137+
concepts,
138+
action
139+
};
140+
const url = `${this._config.basePath}${CONCEPTS_PATH}`;
141+
return wrapToken(this._config, headers => {
142+
return new Promise((resolve, reject) => {
143+
axios.patch(url, data, { headers })
144+
.then((response) => {
145+
if (isSuccess(response)) {
146+
resolve(new Concepts(this._config, response.data.concepts));
147+
} else {
148+
reject(response);
149+
}
150+
}, reject);
151+
});
152+
});
153+
}
154+
};
124155

125156
module.exports = Concepts;

0 commit comments

Comments
 (0)