Sha256: a14a288d5f43f1f5c54f4153430f85c1d6056bc190c4ef21b32fc9f04b25d0d1

Contents?: true

Size: 634 Bytes

Versions: 15

Compression:

Stored size: 634 Bytes

Contents

const mongoose = require('mongoose');
const cql = require('cql-execution');

function Quantity(key, options) {
  mongoose.SchemaType.call(this, key, options, 'Quantity');
}
Quantity.prototype = Object.create(mongoose.SchemaType.prototype);

Quantity.prototype.cast = (quantity) => {
  if (typeof quantity.value === 'undefined') {
    throw new Error(`Quantity: ${quantity} does not have a value`);
  } else if (typeof quantity.unit === 'undefined') {
    throw new Error(`Quantity: ${quantity} does not have a unit`);
  }

  return new cql.Quantity(quantity);
};

mongoose.Schema.Types.Quantity = Quantity;
module.exports = Quantity;

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
cqm-models-1.0.3 app/assets/javascripts/basetypes/Quantity.js
cqm-models-1.0.2 app/assets/javascripts/basetypes/Quantity.js
cqm-models-1.0.1 app/assets/javascripts/basetypes/Quantity.js
cqm-models-1.0.0 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.8.4 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.8.3 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.8.2 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.8.1 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.8.0 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.7.7 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.7.6 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.7.5 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.7.4 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.7.3 app/assets/javascripts/basetypes/Quantity.js
cqm-models-0.7.2 app/assets/javascripts/basetypes/Quantity.js