appointmentSchema.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. const AppointmentTimeRangeSchema = new mongoose.Schema({
  26. start: { type: String, required: true }, // Example: "09:00"
  27. end: { type: String, required: true } // Example: "10:00"
  28. }, {_id: false});
  29. const WeekdayAppointmentSchema = new mongoose.Schema({
  30. name: { type: String, required: true },
  31. active: { type: Boolean, default: true },
  32. date: { type: String, required: true }, // Stored as YYYY-MM-DD
  33. times: { type: [AppointmentTimeRangeSchema], default: [] } // Array of time ranges
  34. }, {_id: false});
  35. const customTimeSpanSchema = new mongoose.Schema({
  36. week: { type: Number, required: true }, // YYYYWW format (year + week number)
  37. appointments: { type: [WeekdayAppointmentSchema], default: [] } // Array of appointments
  38. }, {_id: false});
  39. /**
  40. * Define a schema for an appointment using mongoose.
  41. *
  42. * @description This schema represents an appointment between a user and a service provider.
  43. * @typedef {Object} AppointmentSchema
  44. * @property {String} user - The ID of the user making the appointment (e.g. "user123").
  45. * @property {String} title - A brief title for the appointment (e.g. " haircut").
  46. * @property {String} description - A longer description of the appointment.
  47. * @property {Date} dueDate - The date and time when the appointment is scheduled.
  48. * @property {String} place - The location where the appointment will take place.
  49. */
  50. /**
  51. * Create a mongoose model for appointments using the defined schema.
  52. *
  53. * @description This model allows you to interact with the appointments collection in your MongoDB database.
  54. * @typedef {Object} Appointment
  55. * @static
  56. */
  57. const appointmentSchema = new mongoose.Schema({
  58. user: {
  59. type: String,
  60. required: true
  61. },
  62. title: {
  63. type: String,
  64. required: true
  65. },
  66. participants: {
  67. type: Number,
  68. required: true
  69. },
  70. description: {
  71. type: String
  72. },
  73. dueDate: {
  74. type: Date,
  75. required: true
  76. },
  77. place: {
  78. type: String
  79. },
  80. duration: {
  81. type: Number,
  82. required: true
  83. },
  84. times: [customTimesSchema],
  85. inputs: [customInputSchema],
  86. timeSpans: [customTimeSpanSchema]
  87. });
  88. /**
  89. * Create a mongoose model for appointments and name it "Appointment".
  90. *
  91. * @description This model allows you to interact with the appointments collection in your MongoDB database.
  92. */
  93. const Appointment = mongoose.model('Appointment', appointmentSchema, 'appointment');
  94. export default Appointment;