eyght-models
Version:
Models for eyght
86 lines (74 loc) • 3.02 kB
JavaScript
let mongoose = require('mongoose');
mongoose.Promise = global.Promise;
let eygClientSchema = new mongoose.Schema({
clientName: {type: 'String'},
dbName: {type: 'String'},
txnHoldingCollectionName: {type: 'String', required: true},
functCurrID: {type: mongoose.Schema.Types.ObjectId, ref: 'genCurr'},
tmzID: {type: mongoose.Schema.Types.ObjectId, ref: 'genTmz'},
contactFName: {type: 'String'},
contactLName: {type: 'String'},
addr1: {type: 'String'},
addr2: {type: 'String'},
addr3: {type: 'String'},
city: {type: 'String'},
stProv: {type: 'String'},
zip: {type: 'String'},
ctryID: {type: mongoose.Schema.Types.ObjectId, ref: 'genCtry'},
clientPh: {type: 'String'},
clientContactPh: {type: 'String'},
clientEmail: {type: 'String'},
clientContactEmail: {type: 'String'},
clientIDDerrick: {type: 'Number'},
fein: {type: 'String'},
mccSic: {type: 'String'},
parentClientID: {type: mongoose.Schema.Types.ObjectId, ref: 'eygClient'},
active: {type: 'Boolean', required: true},
inactDt: {type: 'Date'}, //store all dates in utc
inactRsnID: {type: mongoose.Schema.Types.ObjectId, ref: 'genInactRsn'}
}, {timestamps: true});
module.exports = mongoose.model('eygClient', eygClientSchema, 'eygClient');
/*
old client with error handling examples
let mongoose = require('mongoose');
mongoose.Promise = global.Promise;
let clientModel;
let clientSchema = new mongoose.Schema({
clientID: {type: 'String', required: true}, //need to generate a custom id for this field (15 char max)
clientName: {type: 'String', required: [true, 'server.errors.required.name']},
clientManagerRecId: {type: mongoose.Schema.Types.ObjectId, ref: 'user'},
address: {
addr1: {type: 'String', required: [true, 'server.errors.required.addr1']},
addr2: {type: 'String'},
addr3: {type: 'String'},
city: {type: 'String', required: [true, 'server.errors.required.city']},
stPrv: {type: 'String', required: [true, 'server.errors.required.stPrv']},
zip: {type: 'String', required: [true, 'server.errors.required.zip']},
countryRecId: {type: mongoose.Schema.Types.ObjectId, ref: 'country', required: true}
},
clientPhone: {type: 'String', required: true},
clientEmail: {type: 'String', required: true, unique: 'server.errors.duplicate.email'},
emailTypeRecId: {type: mongoose.Schema.Types.ObjectId, ref: 'email_type', required: true},
salesRepRecId: {type: mongoose.Schema.Types.ObjectId, ref: 'user'},
active: {type: 'Number', required: true},
inactiveDate: {type: 'Date'},
inactiveReason: {type: 'String'}
});
clientSchema.pre('validate', function(next) {
let doc = this;
clientModel
.findOne()
.sort('-clientID')
.exec(function(err, record) {
if (err) return next(err);
else if (!record) {
doc.clientID = 1;
next();
} else {
doc.clientID = Number(record.clientID) + 1;
next();
}
});
});
clientModel = mongoose.model('client', clientSchema);
module.exports = clientModel;*/