chat.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. sort: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. total: {
  64. type: Number,
  65. default: 0,
  66. },
  67. watched: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. typing: {
  72. type: Boolean,
  73. default: false,
  74. },
  75. number: {
  76. type: String,
  77. min: 8,
  78. max: 14,
  79. },
  80. country: {
  81. type: String,
  82. default: false,
  83. },
  84. pinned: {
  85. type: Boolean,
  86. default: false,
  87. },
  88. owner: {
  89. type: SchemaTypes.ObjectId,
  90. ref: 'user',
  91. },
  92. },
  93. { timestamps: true }
  94. );
  95. chatSchema.plugin(mongoosePaginate);
  96. const Chat = model('chat', chatSchema);
  97. module.exports = Chat;