All files / mongoose/lib/helpers/schema idGetter.js

63.63% Statements 7/11
72.72% Branches 8/11
50% Functions 1/2
63.63% Lines 7/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35            1x   15x     15x 4x   11x     11x   11x                              
'use strict';
 
/*!
 * ignore
 */
 
module.exports = function addIdGetter(schema) {
  // ensure the documents receive an id getter unless disabled
  const autoIdGetter = !schema.paths['id'] &&
    schema.paths['_id'] &&
    schema.options.id;
  if (!autoIdGetter) {
    return schema;
  }
  Iif (schema.aliases && schema.aliases.id) {
    return schema;
  }
  schema.virtual('id').get(idGetter);
 
  return schema;
};
 
/**
 * Returns this documents _id cast to a string.
 * @api private
 */
 
function idGetter() {
  if (this._id != null) {
    return this._id.toString();
  }
 
  return null;
}