1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-28 13:48:49 +08:00

Merge pull request #17 from drasko/master

Add comments for device model, fix typos
This commit is contained in:
Drasko DRASKOVIC 2015-10-10 01:40:52 +02:00
commit e6203967bb
2 changed files with 116 additions and 93 deletions

View File

@ -13,109 +13,132 @@ var Schema = mongoose.Schema;
/** /**
* Exports * 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({ var DeviceSchema = new Schema({
name: { name: {
type: String, type: String,
required: true required: false
}, },
description: { description: {
type: String, type: String,
required: false required: false
}, },
creator: { creator: {
type: String, type: String,
required: true, required: false,
}, },
owner: { owner: {
type: String, type: String,
required: true, required: false,
}, },
group: { group: {
type: Array, type: Array,
default: [] default: []
}, },
deviceId: { deviceId: {
type: String, type: String,
required: true, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
}, },
apiKey: { apiKey: {
type: String, type: String,
required: true, required: false,
index: true index: true
}, },
createdAt: { createdAt: {
type: Date, type: Date,
index: true, index: true,
default: Date.now default: Date.now
}, },
isPublic: { isPublic: {
type: Boolean, type: Boolean,
index: true, index: true,
default: false default: false
}, },
online: { online: {
type: Boolean, type: Boolean,
index: true, index: true,
default: false default: false
}, },
lastSeen: { lastSeen: {
type: Date type: Date
}, },
updatedAt: { updatedAt: {
type: Date type: Date
}, },
manufacturerId: { manufacturerId: {
type: String, type: String,
required: false, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
}, },
serialNumber: { serialNumber: {
type: String, type: String,
required: false, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
}, },
productId: { productId: {
type: String, type: String,
required: false, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
}, },
activationCode: { activationCode: {
type: String, type: String,
required: false, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
}, },
deviceLocation: { deviceLocation: {
type: String, type: String,
required: false, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
}, },
firmwareVersion: { firmwareVersion: {
type: String, type: String,
required: false, required: false,
index: true, index: true,
match: /^[0-9a-f]{10}$/ match: /^[0-9a-f]{10}$/
} }
}); });
DeviceSchema.static('exists', function (apikey, deviceid, callback) { 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) { DeviceSchema.static('getDeviceByDeviceId', function (deviceid, callback) {
this.where({ deviceId: deviceid }).findOne(callback); this.where({ deviceId: deviceid }).findOne(callback);
}); });
DeviceSchema.static('getDevicesByApikey', function (apikey, callback) { DeviceSchema.static('getDevicesByApikey', function (apikey, callback) {
this.where('apiKey', apikey).find(callback); this.where('apiKey', apikey).find(callback);
}); });

View File

@ -11,8 +11,8 @@ router.route('/')
/** Create a device (accessed at POST http://localhost:8080/devices) */ /** Create a device (accessed at POST http://localhost:8080/devices) */
.post(function(req, res) { .post(function(req, res) {
conslole.log("req.headers['mainflux_uuid']", req.headers['mainflux_uuid']); console.log("req.headers['mainflux_uuid']", req.headers['mainflux_uuid']);
conslole.log("req.headers['mainflux_token']", req.headers['mainflux_token']); console.log("req.headers['mainflux_token']", req.headers['mainflux_token']);
var device = new Device(); // create a new instance of the Device model 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) device.name = req.body.name; // set the device's name (comes from the request)