简体   繁体   中英

How can I create a schema for timetables in MongoDB that is part of a Teacher Schema?

This is my first post at StackOverFlow and I am coming here to search for some ideas to a project that I am developing.

First of all I have one problem of storing available days at a Teacher Schema, in this aplication a Teacher have his class information and it includes availableDays that represents the days and hours available to Students schedule a class with this Teacher, which can be seen below:

const teacherSchema = new mongoose.Schema({
    classPrice: {
        type: Number,
        required: false,
    },
    education: {
        type: [String],
        required: false,
    },
    degree: {
        type: String,
        required: false,
    },
    availableDays: {
        sunday: {
            type: [String],
            required: false
        },
        monday: {
            type: [String],
            required: false
        },
        tuesday: {
            type: [String],
            required: false
        },
        wednesday: {
            type: [String],
            required: false
        },
        thursday: {
            type: [String],
            required: false
        },
        friday: {
            type: [String],
            required: false
        },
        saturday: {
            type: [String],
            required: false
        },
    },
    subjects: {
        type: [mongoose.Schema.Types.ObjectId],
        ref: 'Subject',
        required: true,
    },
    approved: {
        type: Boolean,
        default: false
    },
    rating: {
        type: Number,
        default: 10
    }
});

That was a "bad" solution to store availableDays . Saving a String Array of schedules. The idea was save this data like this:

sunday: ["08:00", "09:00", "10:00"],
monday: ["11:00", "12:00", "13:00"],
...

I am facing some problems at the entire structure.

  1. When a student select a day, for example: (2020/03/02) - (AAAA/DD/MM). It represents a Wednesday, but at my schema there are no diferences between (2020/03/02) and (2020/10/02).

  2. When a student select a day and a hour to schedule his class. This timestamp should be unavailable to others students, and it doesn't occurs.

I also have other Schema to specify the Class:

const classSchema = mongoose.Schema({
    teacherId:{
        type: String,
        required: true,
    },
    userId: {
        type: String,
        required: true,
    },
    price: {
        type: Number,
        required: true,
    },
****
    time:{
        type: Number,
        required: true,
    },
    day:{
        tipe: String,
        required: true,
    },
*****
    status:{
        accepted: {
            type: Boolean,
            default: false,
        },
        payment: {
            type: Boolean,
            default: false,
        },
        available: {
            type: Boolean,
            default: false,
        }
    }
});

Is this Schema, day and time is the DAY and HOUR that student select from AvailableDays at Teacher Schema.

I am looking for some solution that allows the Teacher to select his own day and hours available to be scheduled. This days and hours can be updated by the Teacher at Profile Edit page.

Everything can be changed since I am at the beginning of this project, and I appreciate any help.

For a complete understanding about this problem. In frontend we are saving the day / time information at Teacher register page like this: Screenshot1

And the student selection is made like this: Screenshot2

After a month I found the solution. At first I create a new Schema on Mongo called "Agenda". That agenda has:

{
 teacherId: mongoose.Schema.Types.ObjectId,
 date: Date(),
 availability: true
}

In that way my teacher creates a lot of "Agendas" which represents the distinct schedule with singular times. And that's it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM