chat.js 767 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const mongoose = require('mongoose');
  2. const { Schema, model, SchemaTypes } = mongoose;
  3. const mongoosePaginate = require('mongoose-paginate-v2');
  4. mongoose.Types.ObjectId.isValid();
  5. const chatSchema = new Schema(
  6. {
  7. companionId: {
  8. type: String,
  9. },
  10. name: {
  11. type: String,
  12. default: null,
  13. },
  14. lastName: {
  15. type: String,
  16. default: null,
  17. },
  18. avatarUrl: {
  19. type: String,
  20. default: null,
  21. },
  22. color: {
  23. type: String,
  24. default: null,
  25. },
  26. online: {
  27. type: String,
  28. default: null,
  29. },
  30. number: {
  31. type: String,
  32. min: 8,
  33. max: 14,
  34. },
  35. owner: {
  36. type: SchemaTypes.ObjectId,
  37. ref: 'user',
  38. },
  39. },
  40. { timestamps: true }
  41. );
  42. chatSchema.plugin(mongoosePaginate);
  43. const Chat = model('chat', chatSchema);
  44. module.exports = Chat;