From 73f083102311266b1e62446aa472935b29ddaad6 Mon Sep 17 00:00:00 2001
From: Moritz Gleissner <moritz@gleissner.de>
Date: Fri, 24 Jan 2025 18:01:22 +0100
Subject: [PATCH] feat(saveSkill): use new endpoint for native values save

---
 src/communication/CommunicationManager.ts | 18 ++++++++++++++++++
 src/services/SkillService.ts              | 22 ++++++++++++----------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/communication/CommunicationManager.ts b/src/communication/CommunicationManager.ts
index d24300ae..1c199b3a 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 3c35dfc7..7ccdef03 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
-- 
GitLab