File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 2323
2424const mongoose = require ( 'mongoose' ) ;
2525const Schema = mongoose . Schema ;
26+ const Group = require ( './Group' ) ;
27+
28+ mongoose . Schema . Types . ExplicitAttrsType = Group . ExplicitAttrsType ;
2629
2730const 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} ) ;
Original file line number Diff line number Diff line change 2424const mongoose = require ( 'mongoose' ) ;
2525const 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+
2744const 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
5876module . exports . load = load ;
77+ module . exports . ExplicitAttrsType = ExplicitAttrsType ;
You can’t perform that action at this time.
0 commit comments