chat.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. originalName: {
  20. type: String,
  21. default: null,
  22. },
  23. originalLastName: {
  24. type: String,
  25. default: null,
  26. },
  27. avatarUrl: {
  28. type: String,
  29. default: null,
  30. },
  31. avatarsArr: {
  32. type: Array,
  33. default: [],
  34. },
  35. color: {
  36. type: String,
  37. default: null,
  38. },
  39. online: {
  40. type: String,
  41. default: null,
  42. },
  43. lastMessage: {
  44. type: String,
  45. default: null,
  46. },
  47. lastMessageCreatedAt: {
  48. type: String,
  49. default: null,
  50. },
  51. mute: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. seen: {
  56. type: Number,
  57. default: 0,
  58. },
  59. seenCompanion: {
  60. type: Number,
  61. default: 0,
  62. },
  63. sort: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. total: {
  68. type: Number,
  69. default: 0,
  70. },
  71. watched: {
  72. type: Boolean,
  73. default: false,
  74. },
  75. typing: {
  76. type: Boolean,
  77. default: false,
  78. },
  79. number: {
  80. type: String,
  81. min: 8,
  82. max: 14,
  83. },
  84. country: {
  85. type: String,
  86. default: false,
  87. },
  88. pinned: {
  89. type: Boolean,
  90. default: false,
  91. },
  92. socketId: {
  93. type: String,
  94. default: false,
  95. },
  96. owner: {
  97. type: SchemaTypes.ObjectId,
  98. ref: 'user',
  99. },
  100. },
  101. { timestamps: true }
  102. );
  103. chatSchema.plugin(mongoosePaginate);
  104. const Chat = model('chat', chatSchema);
  105. module.exports = Chat;