From 3b86bf249c1e462925420435b17f242ba2a416c2 Mon Sep 17 00:00:00 2001 From: Drasko DRASKOVIC Date: Sat, 10 Oct 2015 01:17:44 +0200 Subject: [PATCH] Add comments for device model, fix typos Signed-off-by: Drasko DRASKOVIC --- app/models/device.js | 205 +++++++++++++++++++++++------------------- app/routes/devices.js | 4 +- 2 files changed, 116 insertions(+), 93 deletions(-) diff --git a/app/models/device.js b/app/models/device.js index 7f9b607d..9ecdc4c8 100644 --- a/app/models/device.js +++ b/app/models/device.js @@ -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); }); diff --git a/app/routes/devices.js b/app/routes/devices.js index 78a2a737..f05b735b 100644 --- a/app/routes/devices.js +++ b/app/routes/devices.js @@ -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)