{"size": 1590, "ext": "js", "max_stars_repo_path": "routes/api/list.js", "max_stars_repo_name": "Maxx105/shopping_list", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "routes/api/list.js", "max_issues_repo_name": "Maxx105/shopping_list", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "routes/api/list.js", "max_forks_repo_name": "Maxx105/shopping_list", "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": 29.4444444444, "max_line_length": 89, "alphanum_fraction": 0.5742138365}
const express = require("express");
const router = express.Router();
const passport = require("passport");
const listController = require("../../controllers/listController");
const listItemsController = require("../../controllers/ListItemsController");
const path = require("path");
const List = require("../../models/List");
const ListItems = require("../../models/ListItems");

router
    .route("/lists")
    .get(listController.findAll)
    // .post(listController.findOneThenSave);

router
    .route("/lists/:id")
    .get(listController.findById)
    // .post(listController.addItemToList)
    .delete(listController.remove);

router
    .route("/items")
    .get(listItemsController.findAll)
    .put(listItemsController.updateStyle)
    .post(listItemsController.create);

router
    .route("/items/:id")
    .get(listItemsController.findById)
    .delete(listItemsController.remove);

router.post(
    "/lists",
    passport.authenticate("jwt", { session: false }),
    function (req, res) {
        const list = new List(req.body);
        list.save((err) => {
            if (err) {
                res.json({ message: err.message, error: true });
            } else {
                req.user.lists.push(list);
                req.user.save((err) => {
                    if (err) {
                        res.json({ message: err.message, error: true });
                    } else {
                        res.json({ message: "Successfully created list", error: false });
                    }
                });
            }
        });
    }
);

module.exports = router;