Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Device params in payload parser #8

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import { logError } from "../Helpers/log";
import { emitToLiveInspector } from "./LiveInspector";
import { getDeviceParamList } from "./Device";

dayjs.extend(utc);
dayjs.extend(timezone);
Expand All @@ -34,14 +35,17 @@ export const runPayloadParser = async (
throw new Error(`Payload parser file is empty or doesn't exist`);
}

const params = await getDeviceParamList(device.id, false);
const paramsMapped = params.map((x) => ({ key: x.key, value: x.value, sent: x.sent })); // map to remove id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also do:

Suggested change
const paramsMapped = params.map((x) => ({ key: x.key, value: x.value, sent: x.sent })); // map to remove id
const paramsMapped = params.map((x) => ({ ...x, id: undefined })); // map to remove id


const context = vm.createContext({
payload,
raw_payload: options?.rawPayload,
dayjs,
device: {
id: device.id,
tags: device.tags,
params: [],
params: paramsMapped,
},
console: {
log: (...args: any[]) => onLog(device, args, options),
Expand Down