mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +08:00
Add comments for device model, fix typos
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
parent
a3a2c1f449
commit
3b86bf249c
@ -13,109 +13,132 @@ var Schema = mongoose.Schema;
|
||||
/**
|
||||
* Exports
|
||||
*/
|
||||
|
||||
/**
|
||||
* \b Device Schema
|
||||
*
|
||||
* @param name {String} Friendly name of the device
|
||||
* @param description {String} Description of the device
|
||||
* @param creator {String} Device creator
|
||||
* @param owner {String} Owner of the device
|
||||
* @param group {String} Device group that device belongs to
|
||||
* @param deviceId {String} UUID of the device
|
||||
* @param apiKey {String} Authentication token for accessing Mainflux API
|
||||
* @param createdAt {Date} Timestamp of the device creation
|
||||
* @param isPublic {Boolean} Is device publicly shared (not claimed yet)
|
||||
* @param online {Boolean} Is device currently connected
|
||||
* @param lastSeen {Date} When was the device last time connected
|
||||
* @param updatedAt {Date} Timestamp of the last interaction between device and cloud
|
||||
* @param manufacturerId {String} UUID of the manufacturing company
|
||||
* @param serialNumber {String} Manufacturer marks devices by serial number
|
||||
* @param productId {String} devices belong to some product (ex. HUE lights)
|
||||
* @param activationCode {String} 3rd party apps might prefer codes for device claiming
|
||||
* @param deviceLocation {String} Physical location of the device
|
||||
* @param firmwareVersion {String} Needed for the OTA updates
|
||||
*/
|
||||
var DeviceSchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
creator: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
owner: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
group: {
|
||||
type: Array,
|
||||
default: []
|
||||
},
|
||||
deviceId: {
|
||||
type: String,
|
||||
required: true,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
apiKey: {
|
||||
type: String,
|
||||
required: true,
|
||||
index: true
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
index: true,
|
||||
default: Date.now
|
||||
},
|
||||
isPublic: {
|
||||
type: Boolean,
|
||||
index: true,
|
||||
default: false
|
||||
},
|
||||
online: {
|
||||
type: Boolean,
|
||||
index: true,
|
||||
default: false
|
||||
},
|
||||
lastSeen: {
|
||||
type: Date
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date
|
||||
},
|
||||
manufacturerId: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
serialNumber: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
productId: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
activationCode: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
deviceLocation: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
firmwareVersion: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
}
|
||||
name: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
creator: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
owner: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
group: {
|
||||
type: Array,
|
||||
default: []
|
||||
},
|
||||
deviceId: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
apiKey: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
index: true,
|
||||
default: Date.now
|
||||
},
|
||||
isPublic: {
|
||||
type: Boolean,
|
||||
index: true,
|
||||
default: false
|
||||
},
|
||||
online: {
|
||||
type: Boolean,
|
||||
index: true,
|
||||
default: false
|
||||
},
|
||||
lastSeen: {
|
||||
type: Date
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date
|
||||
},
|
||||
manufacturerId: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
serialNumber: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
productId: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
activationCode: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
deviceLocation: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
},
|
||||
firmwareVersion: {
|
||||
type: String,
|
||||
required: false,
|
||||
index: true,
|
||||
match: /^[0-9a-f]{10}$/
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
DeviceSchema.static('exists', function (apikey, deviceid, callback) {
|
||||
this.where({ apiKey: apikey, deviceId: deviceid }).findOne(callback);
|
||||
this.where({ apiKey: apikey, deviceId: deviceid }).findOne(callback);
|
||||
});
|
||||
|
||||
DeviceSchema.static('getDeviceByDeviceId', function (deviceid, callback) {
|
||||
this.where({ deviceId: deviceid }).findOne(callback);
|
||||
this.where({ deviceId: deviceid }).findOne(callback);
|
||||
});
|
||||
|
||||
DeviceSchema.static('getDevicesByApikey', function (apikey, callback) {
|
||||
this.where('apiKey', apikey).find(callback);
|
||||
this.where('apiKey', apikey).find(callback);
|
||||
});
|
||||
|
||||
|
||||
|
@ -11,8 +11,8 @@ router.route('/')
|
||||
/** Create a device (accessed at POST http://localhost:8080/devices) */
|
||||
.post(function(req, res) {
|
||||
|
||||
conslole.log("req.headers['mainflux_uuid']", req.headers['mainflux_uuid']);
|
||||
conslole.log("req.headers['mainflux_token']", req.headers['mainflux_token']);
|
||||
console.log("req.headers['mainflux_uuid']", req.headers['mainflux_uuid']);
|
||||
console.log("req.headers['mainflux_token']", req.headers['mainflux_token']);
|
||||
|
||||
var device = new Device(); // create a new instance of the Device model
|
||||
device.name = req.body.name; // set the device's name (comes from the request)
|
||||
|
Loading…
x
Reference in New Issue
Block a user