Skip to content

Commit a560d54

Browse files
committed
revert change
1 parent e6cf78e commit a560d54

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/model/Device.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
const mongoose = require('mongoose');
2525
const Schema = mongoose.Schema;
26+
const Group = require('./Group');
27+
28+
mongoose.Schema.Types.ExplicitAttrsType = Group.ExplicitAttrsType;
2629

2730
const Device = new Schema({
2831
id: String,
@@ -49,7 +52,7 @@ const Device = new Schema({
4952
internalAttributes: Object,
5053
autoprovision: Boolean,
5154
expressionLanguage: String,
52-
explicitAttrs: Boolean,
55+
explicitAttrs: Group.ExplicitAttrsType,
5356
ngsiVersion: String,
5457
cache: Boolean
5558
});

lib/model/Group.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424
const mongoose = require('mongoose');
2525
const Schema = mongoose.Schema;
2626

27+
class ExplicitAttrsType extends mongoose.SchemaType {
28+
constructor(key, options) {
29+
super(key, options, 'ExplicitAttrsType');
30+
}
31+
// `cast()` takes a parameter that can be anything. You need to
32+
// validate the provided `val` and throw a `CastError` if you
33+
// can't convert it.
34+
cast(val) {
35+
if (!(typeof val === 'boolean' || typeof val === 'string')) {
36+
throw new Error('ExplicitAttrsType: ' + val + ' is not Boolean or String');
37+
}
38+
return val;
39+
}
40+
}
41+
42+
mongoose.Schema.Types.ExplicitAttrsType = ExplicitAttrsType;
43+
2744
const Group = new Schema({
2845
url: String,
2946
resource: String,
@@ -43,9 +60,10 @@ const Group = new Schema({
4360
internalAttributes: Array,
4461
autoprovision: Boolean,
4562
expressionLanguage: String,
46-
explicitAttrs: Boolean,
63+
explicitAttrs: ExplicitAttrsType,
4764
defaultEntityNameConjunction: String,
4865
ngsiVersion: String,
66+
entityNameExp: String,
4967
cache: Boolean
5068
});
5169

@@ -56,3 +74,4 @@ function load(db) {
5674
}
5775

5876
module.exports.load = load;
77+
module.exports.ExplicitAttrsType = ExplicitAttrsType;

0 commit comments

Comments
 (0)