diff --git a/src/communication/CommunicationManager.ts b/src/communication/CommunicationManager.ts index d24300ae462e1c1c72027bea22a41ff9003bb21b..1c199b3a4beeae7376074fefed16fdea42039a66 100644 --- a/src/communication/CommunicationManager.ts +++ b/src/communication/CommunicationManager.ts @@ -162,6 +162,24 @@ export default class CommunicationManager { return this.generateResult<undefined>(endpoint, init, true) } + /** + * Updates the values of a all parameter of a skill. + * Endpoint: /skill/{skillId}/parameters/values/ + * Request: PUT. + * @param json - A list of parameterDataTransfer objects as a json string. + * @param skillId - The id of the skill. + * @returns A Promise that gives a Result with the success status or an error. + */ + public async updateSkillValues( + json: string, + skillId: string + ): Promise<Result<undefined, RestError>> { + const endpoint = `/skill/${encodeURIComponent(skillId)}/parameters/values/` + const init = this.generateRequestInit('PUT', json) + + return this.generateResult<undefined>(endpoint, init, true) + } + /** * Updates the values of a parameter of a skill. * Endpoint: /skill/{skillId}/parameter/{parameterId}/values/ diff --git a/src/services/SkillService.ts b/src/services/SkillService.ts index 3c35dfc71c70d644a7ea7186e614d003491e9941..7ccdef03ae9c47d9fa127cac441a62e3abb75d3f 100644 --- a/src/services/SkillService.ts +++ b/src/services/SkillService.ts @@ -253,6 +253,7 @@ export default class SkillService { const params = skill.parameters if (params === undefined) return true + const dtList = [] for (const param of params) { if ( !param.isInput || @@ -265,17 +266,18 @@ export default class SkillService { } const dt = this.converter.convertParameterToParameterDataTransfer(param) - const json = JSON.stringify(dt.values) - const res = await this.communicationManager.updateSkillParameterValues( - json, - skill.id.id, - param.id.id - ) + dtList.push(dt) + } - if (!res.success) { - NotificationManager.error(`Error saving values for parameter ${param.name}`, res.error) - return false - } + const json = JSON.stringify(dtList) + const res = await this.communicationManager.updateSkillValues( + json, + skill.id.id + ) + + if (!res.success) { + NotificationManager.error(`Error saving values for skill ${skill.id.id}`, res.error) + return false } return true