SHARE
TWEET

Untitled

a guest Jun 18th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const titleEnum = ['Dr.', 'Mr.', 'Ms.', 'Mrs.', 'None'];
  2. const suffixEnum = ['Jr.', 'Sr.','II','III','IV','V', 'Esq'];
  3. const recoveryEnum = ['Recovery', 'Normal'];
  4. const commEnum = ['Comm','Backup'];
  5.  
  6. var AuthSchema = new Schema (
  7.     {
  8.         dateEffective: {type: Date},
  9.         username: {type: String, required: true, max: 20, trim: true, lowercase: true},
  10.         password: {type: String, required: true, max: 20}
  11.     }
  12. )
  13.  
  14. var NameSchema = new Schema (
  15.     {
  16.         title: {type: String, enum: titleEnum},
  17.         firstName: {type: String, required: true, max: 25, trim: true, uppercase: true},
  18.         middleName: {type: String, required: true, max: 25, trim: true, uppercase: true},
  19.         familyName: {type: String, required: true, max: 25, trim: true, uppercase: true},
  20.         suffix: {type: String, enum: suffixEnum}
  21.         // suffix: {type: String, max: 8, trim: true, uppercase: true}
  22.     }
  23. )
  24.  
  25. var EmailSchema = new Schema (
  26.     {
  27.         emailAddress: {type: String, required: true, max: 25, trim: true, lowercase: true},
  28.         recoveryType: {type: String, enum: recoveryEnum, default: "Normal"},
  29.         commType: {type: String, enum: commEnum, default: 'Comm'}
  30.     }
  31. )
  32.  
  33. var UserSchema = new Schema(
  34.     {
  35.         authData: [AuthSchema],
  36.         nameData: [{type: Schema.Types.ObjectId, ref: 'NameSchema', required: true}],
  37.         emailData: [EmailSchema]
  38. }
  39. )
  40.  
  41. module.exports = {
  42.     Auth: mongoose.model('Auth', AuthSchema),
  43.     Name: mongoose.model('Name', NameSchema),
  44.     Email: mongoose.model('Email', EmailSchema),
  45.     User: mongoose.model('User', UserSchema)
  46. }
  47.      
  48. var User = require('../models/user'),
  49.     Auth = User.Auth,
  50.     Name = User.Name,
  51.     Email= User.Email,
  52.     UserObj = User.User;
  53.  
  54. exports.user_create_get = function(req, res, next) {
  55.     async.parallel({
  56.         auth: function(callback){
  57.             var authObj = new Auth({
  58.                 dateEffective: moment(Date.now,"YYYY MM DD").format("YYYY MM DD"),
  59.                 username: '',
  60.                 password: ''
  61.             })
  62.             callback(this.auth);
  63.         },
  64.         name: function(callback){
  65.             var nameObj = new Name({
  66.                 title: '',
  67.                 firstName: '',
  68.                 middleName: '',
  69.                 lastName: '',
  70.                 suffix: ''
  71.             });
  72.             callback(this.name);
  73.         },
  74.         email: function(callback){
  75.             var emailObj = new Email({
  76.                 emailAddress: '',
  77.                 recoveryType: '',
  78.                 commType: ''
  79.             })
  80.             callback(this.email);
  81.         }
  82.     }, function(err, result){
  83.         if (err) {return next(err);}
  84.         var user = new UserObj({
  85.             authData: [result.auth],
  86.             nameData: [result.name],
  87.             emailData: [result.email]
  88.         })
  89.         res.json(user);
  90.     })
  91. };
  92.      
  93. var User = require('../models/user'),
  94.     Auth = User.Auth,
  95.     Name = User.Name,
  96.     Email= User.Email,
  97.     UserObj = User.User;
  98.  
  99. exports.user_create_get = function(req, res, next) {
  100.     var authObj = new Auth({
  101.         dateEffective: moment(Date.now,"YYYY MM DD").format("YYYY MM DD"),
  102.         username: '',
  103.         password: ''
  104.     });
  105.     var nameObj = new Name({
  106.         title: '',
  107.         firstName: '',
  108.         middleName: '',
  109.         lastName: '',
  110.         suffix: ''
  111.     });
  112.     var emailObj = new Email({
  113.         emailAddress: '',
  114.         recoveryType: '',
  115.         commType: ''
  116.     });
  117.  
  118.     var user = new UserObj({
  119.         authData: [authObj],
  120.         nameData: [nameObj],
  121.         emailData: [emailObj]
  122.     });
  123.     res.json(user);
  124. }
  125.      
  126. app.set('json replacer', function(key, value){
  127.   if (typeof value === "undefined") {
  128.     return null;
  129.   };
  130.   return value;
  131. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top