chat.js 1.3 KB

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