You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

question.js 969B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const mongoose = require('mongoose');
  2. const validator = require('validator');
  3. const QuestionSchema = new mongoose.Schema({
  4. firstName: {
  5. type: String,
  6. required: [true, 'Please provide a name.'],
  7. maxlength: [60, 'Name cannot be more than 60 characters'],
  8. trim: true,
  9. },
  10. lastName: {
  11. type: String,
  12. required: [true, 'Please provide a last name.'],
  13. maxlength: [60, 'Name cannot be more than 60 characters'],
  14. trim: true,
  15. },
  16. email: {
  17. type: String,
  18. required: [true, 'Please provide an email.'],
  19. trim: true,
  20. lowercase: true,
  21. unique: false,
  22. validate(value) {
  23. if (!validator.isEmail(value)) {
  24. throw new Error('Email is invalid');
  25. }
  26. },
  27. },
  28. message: {
  29. type: String,
  30. required: [true, 'Please provide a message/question.'],
  31. trim: true,
  32. },
  33. });
  34. const Question =
  35. mongoose.models.Question ||
  36. mongoose.model('Question', QuestionSchema, 'Questions');
  37. module.exports = Question;