{"size": 1352, "ext": "js", "max_stars_repo_path": "router/deleteRequest.js", "max_stars_repo_name": "toppic-suite/topmsv", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "router/deleteRequest.js", "max_issues_repo_name": "toppic-suite/topmsv", "max_issues_repo_issues_event_min_datetime": "2021-02-19T18:42:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T17:37:42.000Z", "max_forks_repo_path": "router/deleteRequest.js", "max_forks_repo_name": "toppic-suite/topmsv", "max_forks_repo_forks_event_min_datetime": "2021-04-19T11:55:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-19T11:55:08.000Z"}
{"max_stars_count": null, "max_issues_count": 8, "max_forks_count": 1, "avg_line_length": 28.7659574468, "max_line_length": 70, "alphanum_fraction": 0.5924556213}
const express = require("express");
const router = express.Router();
const deleteDataset = require("../library/deleteDataset");
const deleteExperiment = require("../library/deleteExperiment");
const deleteProject = require("../library/deleteProjectNew");

/**
 * Express.js router for /deleteRequest
 * 
 * Delete dataset, experiment, or project with given id and type
 */
let deleteRequest = router.post('/deleteRequest', function (req,res) {
    //console.log('Cookies: ', req.cookies);
    //console.log('Session:', req.session);
    //console.log(req.session.passport.user.profile);
    //console.log(req.session);
    //let uid = req.session.passport.user.profile.uid;
    console.log("hello deleteRequest");
    if (req.session.passport === undefined)
    {
        console.log("no passport");
        res.end();
    }
    else {
        //console.log(req.session.passport.user.profile);
        let uid = req.session.passport.user.profile.id;
        let type = req.query.type;
        let id = req.query.id;

        if (type === 'datasetID') {
            deleteDataset(id);
            res.end();
        }

        if (type === 'eid') {
            deleteExperiment(id);
            res.end();
        }

        if (type === 'pid') {
            deleteProject(id);
            res.end();
        }
    }
});

module.exports = deleteRequest;