2022-12-16 02:06:14 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
|
|
|
|
|
|
|
|
export default (id: number, node: Partial<Node>, include: string[] = []): Promise<Node> => {
|
|
|
|
const data = {};
|
|
|
|
|
2023-01-12 19:31:47 +00:00
|
|
|
Object.keys(node).forEach(key => {
|
2022-12-16 02:06:14 +00:00
|
|
|
const key2 = key
|
|
|
|
.replace('HTTP', 'Http')
|
|
|
|
.replace('SFTP', 'Sftp')
|
|
|
|
.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
|
|
|
|
// @ts-ignore
|
|
|
|
data[key2] = node[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.patch(`/api/application/nodes/${id}`, data, { params: { include: include.join(',') } })
|
|
|
|
.then(({ data }) => resolve(rawDataToNode(data)))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|