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.ts 1.0KB

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