Skip to content

Commit

Permalink
revert change
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Aug 22, 2022
1 parent e6cf78e commit a560d54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/model/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Group = require('./Group');

mongoose.Schema.Types.ExplicitAttrsType = Group.ExplicitAttrsType;

const Device = new Schema({
id: String,
Expand All @@ -49,7 +52,7 @@ const Device = new Schema({
internalAttributes: Object,
autoprovision: Boolean,
expressionLanguage: String,
explicitAttrs: Boolean,
explicitAttrs: Group.ExplicitAttrsType,
ngsiVersion: String,
cache: Boolean
});
Expand Down
21 changes: 20 additions & 1 deletion lib/model/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

class ExplicitAttrsType extends mongoose.SchemaType {
constructor(key, options) {
super(key, options, 'ExplicitAttrsType');
}
// `cast()` takes a parameter that can be anything. You need to
// validate the provided `val` and throw a `CastError` if you
// can't convert it.
cast(val) {
if (!(typeof val === 'boolean' || typeof val === 'string')) {
throw new Error('ExplicitAttrsType: ' + val + ' is not Boolean or String');
}
return val;
}
}

mongoose.Schema.Types.ExplicitAttrsType = ExplicitAttrsType;

const Group = new Schema({
url: String,
resource: String,
Expand All @@ -43,9 +60,10 @@ const Group = new Schema({
internalAttributes: Array,
autoprovision: Boolean,
expressionLanguage: String,
explicitAttrs: Boolean,
explicitAttrs: ExplicitAttrsType,
defaultEntityNameConjunction: String,
ngsiVersion: String,
entityNameExp: String,
cache: Boolean
});

Expand All @@ -56,3 +74,4 @@ function load(db) {
}

module.exports.load = load;
module.exports.ExplicitAttrsType = ExplicitAttrsType;

0 comments on commit a560d54

Please sign in to comment.