{"size": 953, "ext": "js", "max_stars_repo_path": "src/controllers/schedule.controller.js", "max_stars_repo_name": "404Stud-io/prismaxBE", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/controllers/schedule.controller.js", "max_issues_repo_name": "404Stud-io/prismaxBE", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/controllers/schedule.controller.js", "max_forks_repo_name": "404Stud-io/prismaxBE", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.7666666667, "max_line_length": 94, "alphanum_fraction": 0.6967471144}
const Schedule = require('../models/schedule');

exports.getSchedules = async (req, res) => {
    const schedules = await Schedule.find();
    res.json(schedules)
}

exports.getSchedule = async (req, res) => {
    const schedule = await Schedule.findById(req.params.scheduleId);
    res.status(200).json(schedule)
}

exports.createSchedule = async(req, res) => {
    const { timeInit, timeEnd, presentation, speaker } = req.body
    const newSchedule = new Schedule({ timeInit, timeEnd, presentation, speaker });
    const scheduleSaved = await newSchedule.save()
    res.status(201).json(scheduleSaved)
}

exports.updateSchedule = async (req, res) => {
    const updateSchedule = await Schedule.findByIdAndUpdate(req.params.scheduleId, req.body, {
        new: true
    })
    res.status(200).json(updateSchedule)
}

exports.deleteSchedule = async (req, res) => {
    await Schedule.findByIdAndDelete(req.params.scheduleId)
    res.status(204).json()
}