Strip extraneous properties from task objects

This commit is contained in:
Zaid Humaimidi committed 2023-08-28 18:19:23 -07:00
1 parent ea956fbc9c
commit 4b0d1786dd
2 files changed
+8 -5

No files matched your search

+7 -4
View File
@@ -21,7 +21,7 @@ import m from "mithril";
import { stringify } from "../lib/common/expression/parser";
import { or, and, evaluate } from "../lib/common/expression/util";
import memoize from "../lib/common/memoize";
import { QueryOptions, Expression } from "../lib/types";
import { QueryOptions, Expression, Task } from "../lib/types";
import * as notifications from "./notifications";
import { configSnapshot, genieacsVersion } from "./config";
import { QueueTask } from "./task-queue";
@@ -60,7 +60,6 @@ const resources: Resources = {};
for (const r of [
"devices",
"faults",
"files",
"presets",
"provisions",
"virtualParameters",
@@ -596,15 +595,19 @@ export function postTasks(
deviceId: string,
tasks: QueueTask[]
): Promise<string> {
const tasks2: Task[] = [];
for (const t of tasks) {
t.status = "pending";
t.device = deviceId;
const t2 = Object.assign({}, t);
delete t2.device;
delete t2.status;
tasks2.push(t2);
}
return xhrRequest({
method: "POST",
url: `api/devices/${encodeURIComponent(deviceId)}/tasks`,
body: tasks,
body: tasks2,
extract: (xhr) => {
if (xhr.status === 403) throw new Error("Not authorized");
if (!xhr.status) throw new Error("Server is unreachable");
+1 -1
View File
@@ -98,7 +98,7 @@ export function commit(
_tasks: QueueTask[]
) => void
): Promise<void> {
const devices: { [deviceId: string]: any[] } = {};
const devices: { [deviceId: string]: QueueTask[] } = {};
if (!canQueue(tasks))
return Promise.reject(new Error("Too many tasks in queue"));