Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. /**
  2. * List of Articles
  3. */
  4. exports.list = function (req, res) {
  5. Article.find({ 'user.displayName': 'GIGANTOR !' }).sort('-created').populate('user', 'displayName').exec(function (err, articles) {
  6. if (err) {
  7. return res.status(422).send({
  8. message: errorHandler.getErrorMessage(err)
  9. });
  10. } else {
  11. res.json(articles);
  12. }
  13. });
  14. };
  15.  
  16. 'use strict';
  17.  
  18. /**
  19. * Module dependencies
  20. */
  21. var mongoose = require('mongoose'),
  22. Schema = mongoose.Schema;
  23.  
  24. /**
  25. * Article Schema
  26. */
  27. var ArticleSchema = new Schema({
  28. created: {
  29. type: Date,
  30. default: Date.now
  31. },
  32. title: {
  33. type: String,
  34. default: '',
  35. trim: true,
  36. required: 'Title cannot be blank'
  37. },
  38. content: {
  39. type: String,
  40. default: '',
  41. trim: true,
  42. required: 'Content cannot be blank'
  43. },
  44. user: {
  45. type: Schema.ObjectId,
  46. ref: 'User'
  47. }
  48. });
  49.  
  50. mongoose.model('Article', ArticleSchema);
  51.  
  52. /**
  53. * User Schema
  54. */
  55. var UserSchema = new Schema({
  56. displayName: {
  57. type: String,
  58. trim: true
  59. },
  60. email: {
  61. type: String,
  62. index: {
  63. unique: true,
  64. sparse: true // For this to work on a previously indexed field, the index must be dropped & the application restarted.
  65. },
  66. lowercase: true,
  67. trim: true,
  68. default: '',
  69. validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
  70. },
  71. username: {
  72. type: String,
  73. unique: 'Username already exists',
  74. required: 'Please fill in a username',
  75. validate: [validateUsername, 'Please enter a valid username: 3+ characters long, non restricted word, characters "_-.", no consecutive dots, does not begin or end with dots, letters a-z and numbers 0-9.'],
  76. lowercase: true,
  77. trim: true
  78. },
  79. password: {
  80. type: String,
  81. default: ''
  82. },
  83. salt: {
  84. type: String
  85. },
  86. provider: {
  87. type: String,
  88. required: 'Provider is required'
  89. },
  90. providerData: {},
  91. additionalProvidersData: {},
  92. roles: {
  93. type: [{
  94. type: String,
  95. enum: ['user', 'admin']
  96. }],
  97. default: ['user'],
  98. required: 'Please provide at least one role'
  99. },
  100. updated: {
  101. type: Date
  102. },
  103. created: {
  104. type: Date,
  105. default: Date.now
  106. },
  107. /* For reset password */
  108. resetPasswordToken: {
  109. type: String
  110. },
  111. resetPasswordExpires: {
  112. type: Date
  113. }
  114. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement