UNPKG

mf-mongoose-validation

Version:

Validate extended data types, field lengths, arrays, optional values, and the like.

44 lines (31 loc) 1.59 kB
/* jshint -W101 */ var $ = require('../../../../src/utils'), _ = require('lodash'), enums = require('../enums'), mongoose = require('mongoose'); var memberId = $.uuids.init(); // var testPlugin = require('../../../../src/to-dto.plugin.js'); var testPlugin = require('../../../../src/validate.plugin.js'); var hobbySchema = mongoose.Schema({ n : { type: String, name: 'Name', required: true, trim: true, minLength: 2, maxLength: 255 } }); var personSchema = mongoose.Schema({ _id : { type: String, name: 'ID', default: $.uuids.init }, s : { type: String, name: 'SSN', required: true, trim: true, minLength: 9, maxLength: 9, validChars: '0123456789', show: '> 50' }, f : { type: String, name: 'First Name', key: 'name.first', required: true, trim: true }, m : { type: String, name: 'Middle Name', key: 'name.middle', trim: true }, l : { type: String, name: 'Last Name', key: 'name.last', required: true, trim: true }, bm : { type: Number, name: 'Birth Month', key: 'dob.month', min: 1, max: 12 }, bd : { type: Number, name: 'Birth Day', key: 'dob.day', min: 1, max: 31 }, by : { type: Number, name: 'Birth Year', key: 'dob.year', min: 1900, max: 2016 }, h : { type: [ hobbySchema ], name: 'Hobbies', required: true, minQty: 1, maxQty: 10 } }); personSchema.plugin(testPlugin); // personSchema.plugin(testPlugin, { // member: { // uuid : 'uid', // default : memberId // } // }); var model = mongoose.model('Person', personSchema); module.exports = model;