SHARE
TWEET

Untitled

a guest Jun 17th, 2019 83 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: [NameSchema],
  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.     var authObj = new Auth({
  56.         dateEffective: moment(Date.now(),"YYYY MM DD").format("YYYY MM DD"),
  57.         username: '',
  58.         password: ''
  59.     });
  60.     var nameObj = new Name({
  61.         title: '',
  62.         firstName: '',
  63.         middleName: '',
  64.         lastName: '',
  65.         suffix: ''
  66.     });
  67.     var emailObj = new Email({
  68.         emailAddress: '',
  69.         recoveryType: '',
  70.         commType: ''
  71.     });
  72.  
  73.     var user = new UserObj({
  74.         authData: [authObj],
  75.         nameData: [nameObj],
  76.         emailData: [emailObj]
  77.     });
  78.     res.json(user);
  79. }
  80.      
  81. var User = require('../models/user'),
  82.     Auth = User.Auth,
  83.     Name = User.Name,
  84.     Email= User.Email,
  85.     UserObj = User.User;
  86.  
  87. exports.user_create_get = function(req, res, next) {
  88.     async.parallel({
  89.         auth: function(callback){
  90.             var authObj = new Auth({
  91.                 dateEffective: moment(Date.now,"YYYY MM DD").format("YYYY MM DD"),
  92.                 username: '',
  93.                 password: ''
  94.             })
  95.             callback(this.auth);
  96.         },
  97.         name: function(callback){
  98.             var nameObj = new Name({
  99.                 title: '',
  100.                 firstName: '',
  101.                 middleName: '',
  102.                 familyName: '',
  103.                 suffix: ''
  104.             });
  105.             callback(this.name);
  106.         },
  107.         email: function(callback){
  108.             var emailObj = new Email({
  109.                 emailAddress: '',
  110.                 recoveryType: '',
  111.                 commType: ''
  112.             })
  113.             callback(this.email);
  114.         }
  115.     }, function(err, result){
  116.         if (err) {return next(err);}
  117.         var user = new UserObj({
  118.             authData: [result.auth],
  119.             nameData: [result.name],
  120.             emailData: [result.email]
  121.         })
  122.         res.json(user);
  123.     })
  124. };
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