misc_pterodactyl-panel/resources/scripts/api/admin/nodes/updateNode.ts

24 lines
762 B
TypeScript
Raw Normal View History

2021-01-30 20:53:47 +00:00
import http from '@/api/http';
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
2021-02-11 17:21:49 +00:00
export default (id: number, node: Partial<Node>, include: string[] = []): Promise<Node> => {
2021-02-11 17:32:13 +00:00
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];
});
2021-01-30 20:53:47 +00:00
return new Promise((resolve, reject) => {
http.patch(`/api/application/nodes/${id}`, {
2021-02-11 17:32:13 +00:00
...data,
2021-01-30 20:53:47 +00:00
}, { params: { include: include.join(',') } })
.then(({ data }) => resolve(rawDataToNode(data)))
.catch(reject);
});
};