added handling for development server file system

This commit is contained in:
David Baldwynn 2015-07-29 17:32:46 -07:00
parent c271052be3
commit 4be6210134
2 changed files with 20 additions and 21 deletions

View file

@ -95,18 +95,14 @@ var FormSchema = new Schema({
}, },
font: String, font: String,
<<<<<<< HEAD
backgroundImage: { type: Schema.Types.Mixed } backgroundImage: { type: Schema.Types.Mixed }
=======
backgroundImage: type: Schema.Types.Mixed
>>>>>>> 33243bea2a1f74f8f417b240f5ad068c1d05c6bd
} }
}); });
//Delete template PDF of current Form //Delete template PDF of current Form
FormSchema.pre('remove', function (next) { FormSchema.pre('remove', function (next) {
if(this.pdf){ if(this.pdf && process.env.NODE_ENV === 'development'){
//Delete template form //Delete template form
fs.unlink(this.pdf.path, function(err){ fs.unlink(this.pdf.path, function(err){
if (err) throw err; if (err) throw err;

View file

@ -106,23 +106,26 @@ UserSchema.virtual('displayName').get(function () {
//Create folder for user's pdfs //Create folder for user's pdfs
UserSchema.pre('save', function (next) { UserSchema.pre('save', function (next) {
if(!this.username || this.username !== this.email){ if(process.env.NODE_ENV === 'development'){
this.username = this.email; if(!this.username || this.username !== this.email){
} this.username = this.email;
var newDestination = path.join(config.pdfUploadPath, this.username.replace(/ /g,'')), }
stat = null; var newDestination = path.join(config.pdfUploadPath, this.username.replace(/ /g,'')),
stat = null;
try { try {
stat = fs.statSync(newDestination); stat = fs.statSync(newDestination);
} catch (err) { } catch (err) {
fs.mkdirSync(newDestination); fs.mkdirSync(newDestination);
} }
if (stat && !stat.isDirectory()) { if (stat && !stat.isDirectory()) {
// console.log('Directory cannot be created'); // console.log('Directory cannot be created');
next( new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"') ); next( new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"') );
}else{ }else{
next(); next();
} }
}
next();
}); });
/** /**