fpl-mongoose-plugins
Helper project to instantiate any of the installed fpl-mongoose plugins.
Installation
npm install --save fpl-mongoose-plugins
New Version & Owner
Ownership has been transferred to MEAN Factory and is available under their mf-mongoose-plugins package.
No updates will be made to this project. Please replace all instances with the new version from MEAN Factory.
Usage
Note the fpl
variable below. This one call replaces the need to specify a separate require()
statement for each of the plugins;
var $ = require('fpl-utils.node'),
config = require('../../../config'),
enums = require('../enums'),
fpl = require('fpl-mongoose-plugins'),
mongoose = require('mongoose'),
var maxYear = (new Date()).getFullYear();
var personSchema = new mongoose.Schema({
_id : { type: String, default: $.uuids.init },
s : { type: String, name: 'SSN', required: true, trim: true, hide: '< 30', minLength: 9, maxLength: 9, validChars: '0123456789' },
p : { type: String, name: 'Name Prefix', key: 'name.prefix', enum: enums.NAME_PREFIX.ids },
f : { type: String, name: 'First Name', key: 'name.first', trim: true, required: true, minLength: 2, maxLength: 50 },
m : { type: String, name: 'Middle Name', key: 'name.first', trim: true, minLength: 2, maxLength: 50 },
l : { type: String, name: 'Last Name', key: 'name.first', trim: true, required: false, minLength: 2, maxLength: 50 },
p : { type: String, name: 'Name Suffix', key: 'name.suffix', enum: enums.NAME_SUFFIX.ids },
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: maxYear }
// ac : { type: Date, required: true }, // Created Date
// au : { type: Date }, // Updated Date
// ad : { type: Date }, // Deleted Date
// am : { type: String, required: true } // Audit Member
});
// PLUGINS ---------------------------------------------------------------------
personSchema.plugin(fpl.audittrail, {
created: {
hide : '< ' + USER
}
updated: {
hide : '< ' + USER
}
member: {
uuid : 'uid',
show : '>= ' + USER
}
});
personSchema.plugin(fpl.dto);
personSchema.plugin(fpl.softdelete);
personSchema.plugin(fpl.vaidate);
// INDICES ---------------------------------------------------------------------
personSchema.index({
s : 1,
ad : 1
}, { unique: true });
module.exports = mongoose.model('Person', personSchema);
Related Projects
The following projects have been designed specifically to work with each other:
fpl-mongoose-audittrail###
Track who and when documents are created and updated without complex programming. Compare and contract different versions of each document.
fpl-mongoose-dto
Convert to/from JSON DTO while applying optional level-based hiding.
fpl-mongoose-softdelete
Increase data integrity by retaining historical data and preventing data from being permanently deleted. Each delete
operation causes the document to be marked as "deleted" and subsequently hidden from result sets.
fpl-mongoose-validate
Provides additional validation for extended data types, field lengths, arrays, and other useful features.
And, of course...
fpl-mongoose-plugins (this plugin)
Helper project to instantiate any of the installed fpl-mongoose plugins.
Contact Information
MEAN Factory
support@meanfactory.com
www.MEANFactory.com
Original Author
Fred Lackey
fred.lackey@gmail.com
www.fredlackey.com