templates/mongoose_template.js.erb in cqm-models-1.0.3 vs templates/mongoose_template.js.erb in cqm-models-1.1.1.0
- old
+ new
@@ -1,30 +1,38 @@
-const mongoose = require('mongoose');
+const mongoose = require('mongoose/browser');
+<% unless datatype.downcase == 'component' || datatype.downcase == 'facilitylocation' %>
+<% unless datatype.downcase == 'id' %>const { IdSchema } = require('./Id');<% end %>
const { DataElementSchema } = require('./basetypes/DataElement');
const Code = require('./basetypes/Code');
const Interval = require('./basetypes/Interval');
const Quantity = require('./basetypes/Quantity');
const DateTime = require('./basetypes/DateTime');
-<% unless datatype.downcase.include? 'component' %>const { ComponentSchema } = require('./Component');<% end %>
-<% unless datatype.downcase.include? 'facilitylocation' %>const { FacilityLocationSchema } = require('./FacilityLocation');<% end %>
-<% unless datatype.downcase == 'id' %>const { IdSchema } = require('./Id');<% end %>
const Any = require('./basetypes/Any');
+const { ComponentSchema } = require('./attributes/Component');
+const { FacilityLocationSchema } = require('./attributes/FacilityLocation');
+<% else %>
+const Code = require('../basetypes/Code');
+const Interval = require('../basetypes/Interval');
+const Quantity = require('../basetypes/Quantity');
+const DateTime = require('../basetypes/DateTime');
+const Any = require('../basetypes/Any');
+<% end %>
const [Number, String] = [
mongoose.Schema.Types.Number,
mongoose.Schema.Types.String,
];
-<% unless datatype == 'Component' || datatype == 'FacilityLocation' %>
-const <%= datatype -%>Schema = DataElementSchema({
+
+const <%= datatype -%>Schema = <% unless datatype == 'Component' || datatype == 'FacilityLocation' %>DataElementSchema<% else %>new mongoose.Schema<%- end %>({
<%- for attribute in attrs_with_extras -%>
- <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
+ <% if attribute[:default] %><%= attribute[:name] %>: { type: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>, default: '<%= attribute[:default] %>' },<% else %><%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,<%- end %>
<%- end %>
});
-<% else %>
-const <%= datatype -%>Schema = new mongoose.Schema({
- <%- for attribute in attrs_with_extras -%>
- <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
- <%- end %>
-});
-<% end %>
+
module.exports.<%= datatype %>Schema = <%= datatype %>Schema;
-module.exports.<%= datatype %> = mongoose.model('<%= datatype %>', <%= datatype %>Schema);
+class <%= datatype %> extends mongoose.Document {
+ constructor(object) {
+ super(object, <%= datatype %>Schema);
+ this._type = 'QDM::<%= datatype %>';
+ }
+}
+module.exports.<%= datatype %> = <%= datatype %>;