From f7904048453a82a9a405f3f4c85ea7936f1c90c4 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Thu, 11 Feb 2021 10:32:13 -0700 Subject: [PATCH] admin(ui): fix updateNode api request --- app/Models/Node.php | 2 +- resources/scripts/api/admin/nodes/updateNode.ts | 15 ++++++++++++++- .../admin/nodes/NodeSettingsContainer.tsx | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Models/Node.php b/app/Models/Node.php index ae7cbf60f..b91e29d54 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -107,7 +107,7 @@ class Node extends Model 'name' => 'required|regex:/^([\w .-]{1,100})$/', 'description' => 'string|nullable', 'location_id' => 'required|exists:locations,id', - 'database_host_id' => 'required|exists:database_hosts,id', + 'database_host_id' => 'sometimes|nullable|exists:database_hosts,id', 'public' => 'boolean', 'fqdn' => 'required|string', 'listen_port_http' => 'required|numeric|between:1,65535', diff --git a/resources/scripts/api/admin/nodes/updateNode.ts b/resources/scripts/api/admin/nodes/updateNode.ts index b87a8802a..32547312d 100644 --- a/resources/scripts/api/admin/nodes/updateNode.ts +++ b/resources/scripts/api/admin/nodes/updateNode.ts @@ -2,9 +2,22 @@ import http from '@/api/http'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; export default (id: number, node: Partial, include: string[] = []): Promise => { + const data = {}; + + Object.keys(node).forEach((key) => { + const key2 = key + .replace('HTTP', 'Http') + .replace('SFTP', 'Sftp') + .replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`); + // @ts-ignore + data[key2] = node[key]; + }); + + console.log(data); + return new Promise((resolve, reject) => { http.patch(`/api/application/nodes/${id}`, { - ...node, + ...data, }, { params: { include: include.join(',') } }) .then(({ data }) => resolve(rawDataToNode(data))) .catch(reject); diff --git a/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx b/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx index 062fbdd83..3b26ffa7b 100644 --- a/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx +++ b/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx @@ -22,6 +22,7 @@ interface Values { publicPortHTTP: number; listenPortSFTP: number; publicPortSFTP: number; + scheme: string; } export default () => { @@ -61,6 +62,7 @@ export default () => { publicPortHTTP: node.publicPortHTTP, listenPortSFTP: node.listenPortSFTP, publicPortSFTP: node.publicPortSFTP, + scheme: node.scheme, }} validationSchema={object().shape({ name: string().required().max(191),