Created
October 13, 2015 20:42
-
-
Save wkentdag/14784e139eb8b044dffb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependencies. | |
*/ | |
var mongoose = require('mongoose'), | |
NoteSchema = require('./note'), | |
LoanSchema = require('./loan'), | |
Loan = mongoose.model('Loan'), | |
util = require('util'), | |
Schema = mongoose.Schema; | |
/** | |
* Company Schema - base class | |
*/ | |
function CompanySchema() { | |
Schema.apply(this, arguments); | |
this.add({ | |
created: { | |
type: Date, | |
default: Date.now | |
}, | |
user: { | |
type: Schema.ObjectId, | |
ref: 'User' | |
}, | |
// CONTACT INFO | |
name: { | |
type: String, | |
default: '', | |
required: 'Please enter a Company name', | |
trim: true | |
}, | |
longName: { | |
type: String, | |
default: '', | |
trim: true | |
}, | |
companyType: { | |
type: String, | |
required: 'Please enter a business type for this Company.', | |
trim: true | |
}, | |
address: { | |
street: { | |
type: String, | |
trim: true, | |
required: 'Please enter a street address.' | |
}, | |
city: { | |
type: String, | |
trim: true, | |
required: 'Please enter a city.' | |
}, | |
state: { | |
type: String, | |
enum: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'], | |
required: 'Please enter a state.' | |
}, | |
zip: { | |
type: Number, | |
required: 'Please enter a zip code.' | |
} | |
}, | |
phone: { | |
primary: { | |
type: String, | |
required: 'Please enter a contact phone number.' | |
}, | |
secondary: String, | |
fax: String | |
}, | |
email: { | |
type: String, | |
trim: true | |
}, | |
website: { | |
type: String, | |
trim: true | |
}, | |
contactPerson: { | |
type: String, | |
trim: true, | |
required: 'Please enter the name of a contact person for this Company.' | |
}, | |
socketLineOfBusiness: { | |
type: String, | |
enum: ['tech','medical','other'], | |
required: 'Please specify the Socket Line of Business' | |
}, | |
status:{ | |
type: String, | |
enum: ['active','inactive','closed','work-out','suspended'], | |
required: 'Please specify a status for this company. Valid values are: active, inactive, closed, work-out, and suspended' | |
}, | |
statementDate:{ | |
type: Date | |
}, | |
loans: [{ | |
type: Schema.ObjectId, | |
ref: 'Loan' | |
}], | |
files: [String], | |
notes: [NoteSchema] | |
}); | |
} | |
util.inherits(CompanySchema, Schema); | |
var CompanySchema = new CompanySchema(); | |
CompanySchema.post('save', function(doc) { | |
if (doc.status === 'inactive') { | |
Loan.find({borrower: doc._id}).exec(function(err, loans) { | |
if (!err && loans) { | |
loans.map(function(loan) { | |
loan.status = 'inactive'; | |
console.log(loan._id + ':\t' + loan.status); | |
loan.save(); | |
}); | |
} | |
}); | |
} | |
}); | |
module.exports.Company = mongoose.model('Company', CompanySchema); | |
module.exports.CompanySchema = CompanySchema; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependencies. | |
*/ | |
var mongoose = require('mongoose'), | |
Company = require('./company'), | |
Schema = mongoose.Schema; | |
/** | |
* Lender Schema | |
*/ | |
var LenderSchema = new Company.CompanySchema({ | |
test: { | |
type: String | |
} | |
}); | |
module.exports = Company.Company.discriminator('lender', LenderSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment