Algorithm for creating Teacher’s timetable using javascript and expressjs

I am trying to make a timetable generator app for teachers. I am facing a few problems when making this app I do not know what algorithm or what tactics I should use to complete this app, so I request your suggestion, thank you.

I am not a professional in this field, I have never made a timetable app before any expert can guide me through this project will be very helpful.

Resources/languages I am using:

  1. MongoDB (database)
  2. ExpressJS (backend)
  3. ReactJS (frontend)
  4. NodeJS

App Problems:
I have to make this app in such a way that it should generate timetable for all 12 classes in a school at once and it should not overlap teachers. Creating a single class timetable is easy but keeping in mind this overlap issue is a headache.

  1. When generating the timetable, I want that the app should generate time table for all the classes at once(ex-12 classes in a school) and making sure that teachers do not overlap each others lecture at same day at same time. Ex- Amit is teaching maths, the app generated timetable but he has 2 lectures on monday and same time i.e. 10am at 2 different classes.

  2. There are different priority teachers like, main teaching staff, non teaching staff, and so on. So they have priorities to take class if a particular subject teacher is not available. Ex – Amit is absent so priority 2 teacher will be assigned i.e. non teaching staff.

  3. How should I store the json data. I mean what should be the format of it in MongoDB schema model, Ex – The current Schema looks like this is there any improvement needed.

const TimetableSchema = new mongoose.Schema({
  subject: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "Subject",
    required: true,
  },
  day: {
    type: String,
    required: true,
    enum: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  },
  period: { type: String, required: true },
  teacher: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "Teacher",
    required: true,
  },
  class: { type: mongoose.Schema.Types.ObjectId, ref: "Class" },
});
  1. Also teachers have there specific subjects to teach so no random teacher selection is allowed.

I am expecting a app which will generate timetable for 12 classes or n number of classes for teachers and without overlapping them.