chat.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const { boolean } = require('joi');
  2. const mongoose = require('mongoose');
  3. const { Schema, model, SchemaTypes } = mongoose;
  4. const mongoosePaginate = require('mongoose-paginate-v2');
  5. mongoose.Types.ObjectId.isValid();
  6. const chatSchema = new Schema(
  7. {
  8. companionId: {
  9. type: String,
  10. },
  11. name: {
  12. type: String,
  13. default: null,
  14. },
  15. lastName: {
  16. type: String,
  17. default: null,
  18. },
  19. avatarUrl: {
  20. type: String,
  21. default: null,
  22. },
  23. color: {
  24. type: String,
  25. default: null,
  26. },
  27. online: {
  28. type: String,
  29. default: null,
  30. },
  31. lastMessage: {
  32. type: String,
  33. default: null,
  34. },
  35. mute: {
  36. type: Boolean,
  37. default: false,
  38. },
  39. seen: {
  40. type: Number,
  41. default: 0,
  42. },
  43. sort: {
  44. type: Boolean,
  45. default: false,
  46. },
  47. total: {
  48. type: Number,
  49. default: 0,
  50. },
  51. watched: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. typing: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. number: {
  60. type: String,
  61. min: 8,
  62. max: 14,
  63. },
  64. owner: {
  65. type: SchemaTypes.ObjectId,
  66. ref: 'user',
  67. },
  68. },
  69. { timestamps: true }
  70. );
  71. chatSchema.plugin(mongoosePaginate);
  72. const Chat = model('chat', chatSchema);
  73. module.exports = Chat;