appointmentSchema.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import mongoose from "mongoose";
  2. const customInputSchema = new mongoose.Schema({
  3. name: {
  4. type: String,
  5. required: true
  6. },
  7. type: {
  8. type: String,
  9. enum: ["tel", "text", "email"],
  10. requried: true
  11. }
  12. },
  13. {_id: false});
  14. const customTimesSchema = new mongoose.Schema({
  15. date: {
  16. type: Date,
  17. required: true
  18. },
  19. available: {
  20. type: Boolean,
  21. default: false
  22. }
  23. },
  24. {_id: false});
  25. /**
  26. * Define a schema for an appointment using mongoose.
  27. *
  28. * @description This schema represents an appointment between a user and a service provider.
  29. * @typedef {Object} AppointmentSchema
  30. * @property {String} user - The ID of the user making the appointment (e.g. "user123").
  31. * @property {String} title - A brief title for the appointment (e.g. " haircut").
  32. * @property {String} description - A longer description of the appointment.
  33. * @property {Date} dueDate - The date and time when the appointment is scheduled.
  34. * @property {String} place - The location where the appointment will take place.
  35. */
  36. /**
  37. * Create a mongoose model for appointments using the defined schema.
  38. *
  39. * @description This model allows you to interact with the appointments collection in your MongoDB database.
  40. * @typedef {Object} Appointment
  41. * @static
  42. */
  43. const appointmentSchema = new mongoose.Schema({
  44. user: {
  45. type: String,
  46. required: true
  47. },
  48. title: {
  49. type: String,
  50. required: true
  51. },
  52. description: {
  53. type: String
  54. },
  55. dueDate: {
  56. type: Date,
  57. required: true
  58. },
  59. place: {
  60. type: String
  61. },
  62. duration: {
  63. type: Number,
  64. required: true
  65. },
  66. times: [customTimesSchema],
  67. inputs: [customInputSchema]
  68. });
  69. /**
  70. * Create a mongoose model for appointments and name it "Appointment".
  71. *
  72. * @description This model allows you to interact with the appointments collection in your MongoDB database.
  73. */
  74. const Appointment = mongoose.model('Appointment', appointmentSchema, 'appointment');
  75. export default Appointment;