chat.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. owner: {
  81. type: SchemaTypes.ObjectId,
  82. ref: 'user',
  83. },
  84. },
  85. { timestamps: true }
  86. );
  87. chatSchema.plugin(mongoosePaginate);
  88. const Chat = model('chat', chatSchema);
  89. module.exports = Chat;