-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathflow.js
51 lines (49 loc) · 1.96 KB
/
flow.js
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
50
51
"use strict";
var JSONAPISerializer = require("jsonapi-serializer").Serializer;
function FlowSerializer(flow) {
this.serialize = function() {
return new JSONAPISerializer("flow", {
keyForAttribute: "underscore_case",
attributes : [ "name", "unit", "objects", "require_signed", "require_encrypted", "dead_notification", "dead_notification_interval", "dead_notification_latest", "permission", "data_type", "mqtt_topic", "track_id", "fusion_algorithm", "ttl", "preprocessor", "influx_db_cloud", "retention", "user_id", "meta" ],
topLevelLinks : {
parent : sprintf("%s/v%s/flows", baseUrl_https, version),
first : flow.pageFirst!==undefined?sprintf("%s/v%s/flows/?page=%s&size=%s", baseUrl_https, version, flow.pageFirst, flow.size):undefined,
prev : flow.pagePrev!==undefined?sprintf("%s/v%s/flows/?page=%s&size=%s", baseUrl_https, version, flow.pagePrev, flow.size):undefined,
next : flow.pageNext!==undefined?sprintf("%s/v%s/flows/?page=%s&size=%s", baseUrl_https, version, flow.pageNext, flow.size):undefined,
last : flow.pageLast!==undefined?sprintf("%s/v%s/flows/?page=%s&size=%s", baseUrl_https, version, flow.pageLast, flow.size):undefined,
},
dataLinks : {
unit : function(flow) {
if ( flow.unit!=="" ) {
return sprintf("%s/v%s/units/%s", baseUrl_https, version, flow.unit);
} else {
return null;
}
},
data : function(flow) {
if ( flow.id!=="" ) {
return sprintf("%s/v%s/data/%s", baseUrl_https, version, flow.id);
} else {
return null;
}
},
self : function(flow) {
if ( typeof flow.id!=="undefined" ) {
return sprintf("%s/v%s/flows/%s", baseUrl_https, version, flow.id);
} else {
return null;
}
},
},
objects: {
attributes : [ "object_id" ],
dataLinks: {
self: function (flow) {
return sprintf("%s/v%s/objects/%s", baseUrl_https, version, flow.object_id);
}
}
}
}).serialize(flow);
};
}
module.exports = FlowSerializer;