Sha256: 5a04f7c8f44b37069123520a183f05995716b73ff648af5b4bc8f961d2ee53ea

Contents?: true

Size: 663 Bytes

Versions: 16

Compression:

Stored size: 663 Bytes

Contents

const mongoose = require('mongoose/browser');
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.value, quantity.unit);
};

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cqm-models-4.2.0 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.1.2 app/assets/javascripts/basetypes/Quantity.js
cqm-models-4.1.1 app/assets/javascripts/basetypes/Quantity.js
cqm-models-4.1.0 app/assets/javascripts/basetypes/Quantity.js
cqm-models-4.0.2 app/assets/javascripts/basetypes/Quantity.js
cqm-models-4.0.1 app/assets/javascripts/basetypes/Quantity.js
cqm-models-4.0.0 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.1.1 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.1.0 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.6 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.5 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.4 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.3 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.2 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.1 app/assets/javascripts/basetypes/Quantity.js
cqm-models-3.0.0 app/assets/javascripts/basetypes/Quantity.js