{"size": 1751, "ext": "js", "max_stars_repo_path": "routes/teacher-route.js", "max_stars_repo_name": "rattanakleng/Student-Management-System", "max_stars_repo_stars_event_min_datetime": "2021-02-16T00:03:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-16T00:03:37.000Z", "max_issues_repo_path": "routes/teacher-route.js", "max_issues_repo_name": "rattanakleng/Student-Management-System", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "routes/teacher-route.js", "max_forks_repo_name": "rattanakleng/Student-Management-System", "max_forks_repo_forks_event_min_datetime": "2021-01-31T01:29:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-04T20:16:36.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 28.2419354839, "max_line_length": 93, "alphanum_fraction": 0.5613934894}
const db = require("../models");
var express = require("express");
const router = express.Router();
// const passport = require("../config/passport");

const isAuthenticated = require("../config/middleware/isAuthenticated");



router.get("/api/teacher", function (req, res) {
    if (!req.user) {
        // The user is not logged in, send back an empty object
        res.json({});
    } else {
        // Here we add an "include" property to our options in our findOne query
        // We set the value to an array of the models we want to include in a left outer join
        // In this case, just db.Post
        db.Teachers.findAll({

        }).then(function (dbTeachers) {
            res.json(dbTeachers);
        });
    }
});

// html route for teachers page

router.get("/teacher", isAuthenticated, (req, res) => {
    //If the user already has an accoutn send them to class page
    db.Teachers.findAll(

    ).then((dbTeachers) => {
        let resultAsJson = dbTeachers.map((dbTeachers) => dbTeachers.toJSON());
        let result = { data: resultAsJson };
        res.render("teacher", result);
    });
});


/* -------------------------------------------------------------------------- */
router.post("/teacher/add/:id", isAuthenticated, async (req) => {
    // eslint-disable-next-line no-unused-vars
    const addTeacher = await db.TeacherStudents.findOrCreate({
        where: {
            StudentId: req.user.id,
            TeacherId: req.params.id

        }
        // createdAt: CURRENT_TIMESTAMP,
        // updatedAt: CURRENT_TIMESTAMP,

    });
    // .then(() => {
    //     res.redirect(307, "/api/login");
    // })
    // .catch(err => {
    //     res.status(401).json(err);
    // });
});


module.exports = router;