{"size": 1358, "ext": "js", "max_stars_repo_path": "controllers/partController.js", "max_stars_repo_name": "cooperbrislain/nearmeans", "max_stars_repo_stars_event_min_datetime": "2021-03-26T19:06:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-26T19:06:44.000Z", "max_issues_repo_path": "controllers/partController.js", "max_issues_repo_name": "cooperbrislain/nearmeans", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "controllers/partController.js", "max_forks_repo_name": "cooperbrislain/nearmeans", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.1153846154, "max_line_length": 62, "alphanum_fraction": 0.4536082474}
const db = require('./../models');

module.exports = {
    createPart: async (req, res) => {
        const { partName } = req.body;
        const thePart = {
            name: partName
        };
        try {
            const result = await db.Part.create(thePart);
            await res.json(result);
        } catch (e) {
            await res.json(e);
        }
    },
    getParts: async (req, res) => {
        try {
            let parts = await db.Part.find();
            await res.json(parts);
        } catch (e) {
            await res.json(e);
        }
    },
    getPart: async (req, res) => {
        const { partId } = req.body;
        try {
            let part = await db.Part.findById(partId);
            await res.json(part);
        } catch (e) {
            await res.json(e);
        }
    },
    updatePart: async (req, res) => {
        const { partId, partData } = req.params;
        try {
            await db.Part.findByIdAndUpdate(partId, partData);
            await res.json({success:true});
        } catch (e) {
            await res.json(e);
        }
    },
    deletePart: async (req, res) => {
        const { partId } = req.params;
        try {
            await db.Part.findByIdAndDelete(partId);
            await res.json({success:true});
        } catch (e) {
            await res.json(e);
        }
    }
};
