Guest User

Untitled

a guest
Jul 30th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import mongoose, { Schema } from 'mongoose';
  2. import bcrypt from 'mongoose-bcrypt';
  3. import timestamps from 'mongoose-timestamp';
  4. import mongooseStringQuery from 'mongoose-string-query';
  5.  
  6. import FollowSchema from './follow';
  7. import PinSchema from './pin';
  8. import ListenSchema from './listen';
  9.  
  10. import PlaylistSchema from './playlist';
  11. import jwt from 'jsonwebtoken';
  12. import config from '../config';
  13. import gravatar from 'gravatar';
  14. import { getStreamClient } from '../utils/stream';
  15.  
  16. export const UserSchema = new Schema({
  17. email: {
  18. type: String,
  19. lowercase: true,
  20. trim: true,
  21. index: true,
  22. unique: true,
  23. required: true
  24. },
  25. username: {
  26. type: String,
  27. lowercase: true,
  28. trim: true,
  29. index: true,
  30. unique: true,
  31. required: true
  32. },
  33. password: {
  34. type: String,
  35. required: true,
  36. bcrypt: true
  37. },
  38. name: {
  39. type: String,
  40. trim: true,
  41. required: true
  42. },
  43. bio: {
  44. type: String,
  45. trim: true,
  46. default: ''
  47. },
  48. url: {
  49. type: String,
  50. trim: true,
  51. default: ''
  52. },
  53. twitter: {
  54. type: String,
  55. trim: true,
  56. default: ''
  57. },
  58. background: {
  59. type: Number,
  60. default: 1
  61. },
  62. interests: {
  63. type: Schema.Types.Mixed,
  64. default: []
  65. },
  66. preferences: {
  67. notifications: {
  68. daily: {
  69. type: Boolean,
  70. default: false
  71. },
  72. weekly: {
  73. type: Boolean,
  74. default: true
  75. },
  76. follows: {
  77. type: Boolean,
  78. default: true
  79. }
  80. }
  81. },
  82. recoveryCode: {
  83. type: String,
  84. trim: true,
  85. default: ''
  86. },
  87. active: {
  88. type: Boolean,
  89. default: true
  90. },
  91. admin: {
  92. type: Boolean,
  93. default: false
  94. }
  95. });
  96.  
  97. UserSchema.plugin(bcrypt);
  98. UserSchema.plugin(timestamps, {
  99. createdAt: { index: true },
  100. updatedAt: { index: true }
  101. });
  102. UserSchema.plugin(mongooseStringQuery);
  103.  
  104. UserSchema.index({ email: 1, username: 1 });
  105.  
  106. module.exports = exports = mongoose.model('User', UserSchema);
Add Comment
Please, Sign In to add comment