| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import mongoose from "mongoose";
- const customInputSchema = new mongoose.Schema({
- name: {
- type: String,
- required: true
- },
- type: {
- type: String,
- enum: ["tel", "text", "email"],
- requried: true
- }
- },
- {_id: false});
- const customTimesSchema = new mongoose.Schema({
- date: {
- type: Date,
- required: true
- },
- available: {
- type: Boolean,
- default: false
- }
- },
- {_id: false});
- const AppointmentTimeRangeSchema = new mongoose.Schema({
- start: { type: String, required: true }, // Example: "09:00"
- end: { type: String, required: true } // Example: "10:00"
- }, {_id: false});
- const WeekdayAppointmentSchema = new mongoose.Schema({
- name: { type: String, required: true },
- active: { type: Boolean, default: true },
- date: { type: String, required: true }, // Stored as YYYY-MM-DD
- times: { type: [AppointmentTimeRangeSchema], default: [] } // Array of time ranges
- }, {_id: false});
- const customTimeSpanSchema = new mongoose.Schema({
- week: { type: Number, required: true }, // YYYYWW format (year + week number)
- appointments: { type: [WeekdayAppointmentSchema], default: [] } // Array of appointments
- }, {_id: false});
- /**
- * Define a schema for an appointment using mongoose.
- *
- * @description This schema represents an appointment between a user and a service provider.
- * @typedef {Object} AppointmentSchema
- * @property {String} user - The ID of the user making the appointment (e.g. "user123").
- * @property {String} title - A brief title for the appointment (e.g. " haircut").
- * @property {String} description - A longer description of the appointment.
- * @property {Date} dueDate - The date and time when the appointment is scheduled.
- * @property {String} place - The location where the appointment will take place.
- */
- /**
- * Create a mongoose model for appointments using the defined schema.
- *
- * @description This model allows you to interact with the appointments collection in your MongoDB database.
- * @typedef {Object} Appointment
- * @static
- */
- const appointmentSchema = new mongoose.Schema({
- user: {
- type: String,
- required: true
- },
- title: {
- type: String,
- required: true
- },
- participants: {
- type: Number,
- required: true
- },
- description: {
- type: String
- },
- dueDate: {
- type: Date,
- required: true
- },
- place: {
- type: String
- },
- duration: {
- type: Number,
- required: true
- },
- times: [customTimesSchema],
- inputs: [customInputSchema],
- timeSpans: [customTimeSpanSchema]
- });
- /**
- * Create a mongoose model for appointments and name it "Appointment".
- *
- * @description This model allows you to interact with the appointments collection in your MongoDB database.
- */
- const Appointment = mongoose.model('Appointment', appointmentSchema, 'appointment');
- export default Appointment;
|