1 |
|
2 | const Model = require("./Model")
|
3 |
|
4 | class Action extends Model {
|
5 |
|
6 | constructor(json, device) {
|
7 | super(json)
|
8 | this.setDevice(device)
|
9 | }
|
10 |
|
11 | defaultFields() {
|
12 | return {
|
13 | userId: {
|
14 | type: String,
|
15 | required: true
|
16 | },
|
17 | deviceId: {
|
18 | type: String,
|
19 | required: true
|
20 | },
|
21 | name: { type: String, required: true },
|
22 | status: String,
|
23 | id: { type: String, required: true }
|
24 | }
|
25 | }
|
26 |
|
27 | setDevice(device) {
|
28 |
|
29 | this.device = device
|
30 |
|
31 | if(device) {
|
32 | this.userId = device.userId
|
33 | this.deviceId = device.id
|
34 | }
|
35 | else {
|
36 | this.userId = null
|
37 | this.deviceId = null
|
38 | }
|
39 |
|
40 | }
|
41 |
|
42 | getDevice() {
|
43 | return this.device || null
|
44 | }
|
45 |
|
46 | }
|
47 |
|
48 | module.exports = Action
|