-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatusCreate.js
More file actions
46 lines (41 loc) · 1.35 KB
/
statusCreate.js
File metadata and controls
46 lines (41 loc) · 1.35 KB
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
exports.action = {
name: 'statusCreate',
description: 'Creates a Status',
version: 1,
inputs: {
required: [ 'printerId' ],
optional: [ 'status', 'pageCount', 'trays', 'consumables' ]
},
outputExample: {},
run: function (api, connection, next) {
var id = connection.params.printerId;
var trays = new Array();
if (connection.params.trays) {
trays = JSON.parse(connection.params.trays);
}
var consumables = new Array();
if (connection.params.consumables) {
consumables = JSON.parse(connection.params.consumables);
}
api.mongoose.model('Printer').findByIdAndUpdate(id, {
status: {
message: connection.params.status,
pageCount: connection.params.pageCount,
timeStamp: new Date(),
trays: trays,
consumables: consumables
},
$push: {
statuses: {
status: connection.params.status,
pageCount: connection.params.pageCount,
timeStamp: new Date(),
trays: trays,
consumables: consumables
}
}
}, function (err) {
next(connection, true);
});
}
};