-
Notifications
You must be signed in to change notification settings - Fork 447
/
Copy pathqueryHistoricTimeseriesDataRequest.ts
49 lines (45 loc) · 1.46 KB
/
queryHistoricTimeseriesDataRequest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// @ts-strict-ignore
import { format } from "date-fns";
import { Resolution } from "src/app/edge/history/shared";
import { ChannelAddress } from "../../../shared/type/channeladdress";
import { JsonrpcRequest } from "../base";
import { JsonRpcUtils } from "../jsonrpcutils";
/**
* Represents a JSON-RPC Request to query Historic Timeseries Data.
*
* <pre>
* {
* "jsonrpc": "2.0",
* "id": UUID,
* "method": "queryHistoricTimeseriesData",
* "params": {
* "timezone": Number,
* "fromDate": YYYY-MM-DD,
* "toDate": YYYY-MM-DD,
* "channels": ChannelAddress[]
* }
* }
* </pre>
*/
export class QueryHistoricTimeseriesDataRequest extends JsonrpcRequest {
private static METHOD: string = "queryHistoricTimeseriesData";
public constructor(
private fromDate: Date,
private toDate: Date,
private channels: ChannelAddress[],
private resolution: Resolution,
) {
super(QueryHistoricTimeseriesDataRequest.METHOD, {
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
fromDate: format(fromDate, "yyyy-MM-dd"),
toDate: format(toDate, "yyyy-MM-dd"),
channels: JsonRpcUtils.channelsToStringArray(channels),
resolution: resolution,
});
// delete local fields, otherwise they are sent with the JSON-RPC Request
delete this.fromDate;
delete this.toDate;
delete this.channels;
delete this.resolution;
}
}