chat.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. mute: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. seen: {
  36. type: Number,
  37. default: 0,
  38. },
  39. total: {
  40. type: Number,
  41. default: 0,
  42. },
  43. watched: {
  44. type: Boolean,
  45. default: false,
  46. },
  47. typing: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. number: {
  52. type: String,
  53. min: 8,
  54. max: 14,
  55. },
  56. owner: {
  57. type: SchemaTypes.ObjectId,
  58. ref: 'user',
  59. },
  60. },
  61. { timestamps: true }
  62. );
  63. chatSchema.plugin(mongoosePaginate);
  64. const Chat = model('chat', chatSchema);
  65. module.exports = Chat;