chat.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. lastMessageCreatedAt: {
  36. type: String,
  37. default: null,
  38. },
  39. mute: {
  40. type: Boolean,
  41. default: false,
  42. },
  43. seen: {
  44. type: Number,
  45. default: 0,
  46. },
  47. sort: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. total: {
  52. type: Number,
  53. default: 0,
  54. },
  55. watched: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. typing: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. number: {
  64. type: String,
  65. min: 8,
  66. max: 14,
  67. },
  68. owner: {
  69. type: SchemaTypes.ObjectId,
  70. ref: 'user',
  71. },
  72. },
  73. { timestamps: true }
  74. );
  75. chatSchema.plugin(mongoosePaginate);
  76. const Chat = model('chat', chatSchema);
  77. module.exports = Chat;