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