Constructor
new DeviceDatabase()
- Source:
- Implements:
- DatabaseInterface
Methods
(async, static) checkPermissions(id, permission_names, user) → {Promise.<void>}
- Source:
Override the default permission checking on the device object and defer to the network instead
Parameters:
Name | Type | Description |
---|---|---|
id |
string | the database id of the object to check permissions for |
permission_names |
Array.<string> | An array of permission names to look for |
user |
Object | the user to check permissions for |
Returns:
- Type
- Promise.<void>
(async, static) create(name, coordinator_id, user, network_id) → {Object}
- Source:
Creates a new device in the database which belongs to user.
1. Generate a client certificate and device id for the new device.
2. Add the new device object to the MongoDB "Devices" collection.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the device. |
coordinator_id |
Object | The id of the coordinator these device is under, should pass null if this is supposed to be a coordinator device. |
user |
Object | The user creating the device. |
network_id |
string | The id of the network where the device will be added. |
Returns:
An object containing the authentication information for the device.
- Type
- Object
(async, static) del(id, user) → {boolean}
- Source:
Deletes a device.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the device to delete. |
user |
Object | The user attempting to delete the device. |
Throws:
User must own the device.
Returns:
True if the device was deleted.
- Type
- boolean
(async, static) get(id) → {Object}
- Source:
Gets the device with id.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the device. |
Returns:
A device object from the MongoDB.
- Type
- Object
(async, static) getByUser(user) → {Array}
- Source:
Gets all the devices belonging to this user.
Parameters:
Name | Type | Description |
---|---|---|
user |
Object | A user object |
Returns:
An array of devices belonging to the user.
- Type
- Array
(async, static) getCollection() → {Object}
- Source:
Helper function to get the collection of devices.
Returns:
The MongoDB collection for devices
- Type
- Object
(async, static) owns(id, user) → {boolean}
- Source:
Determines if user owns the device with id
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the device to check for ownership. |
user |
Object | The user to check for ownership. |
Returns:
True if the user does own the device, false otherwise.
- Type
- boolean
(async, static) update(id, update, user) → {Object}
- Source:
Updates a device.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the device to update. |
update |
Object | The update to apply. |
user |
Object | The user requesting the update. |
Throws:
User must own the device.
Returns:
The updated device.
- Type
- Object