{"size": 1354, "ext": "js", "max_stars_repo_path": "src/server/controllers/meeting-controller.js", "max_stars_repo_name": "neuhausneuhaus/neuhaus-on-demand", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/server/controllers/meeting-controller.js", "max_issues_repo_name": "neuhausneuhaus/neuhaus-on-demand", "max_issues_repo_issues_event_min_datetime": "2021-05-10T09:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T09:09:56.000Z", "max_forks_repo_path": "src/server/controllers/meeting-controller.js", "max_forks_repo_name": "neuhausneuhaus/neuhaus-on-demand", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 25.0740740741, "max_line_length": 119, "alphanum_fraction": 0.5908419498}
const {pool} = require('../db/init');

// *Save a Selected Meeting to DB*
// *Find all meetings based on applicant email*
// *Delete a meeting*
// *Change a meeting*

const meetingController = {
  getAllMeetings: (req, res, next) => {
    pool.query(`SELECT * FROM meeting`)
    .then((result) => {
      console.log('getAllMeetings pool.query then result', result);
      res.meetings = result.rows;
      next();
      // pool.end(() => console.log('pool has ended'));
    }).catch((err) => {
      console.log("ERROR POTATO");
      console.log(err);
      pool.end(() => console.log('pool has ended'));
    });
  },

  getMeetingsByApplicant: (req, res, next) => {
    
    const applicantEmail = req.params.email;

    const query = {
      text:`SELECT meeting.meeting_id, meeting.addedtoneuhauscal, meeting.applicant_id, meeting.gcalid, applicant.email
      FROM meeting
      INNER JOIN applicant
      ON meeting.applicant_id = applicant.applicant_id
      WHERE applicant.email = $1;`,
      values: [applicantEmail]
    }

    pool.query(query, (err, result) => {
      if (err) {
        console.log(err);
      } else {
        res.meetings = result.rows;
        next();
      }
    })
  },
  changeMeeting: (req, res, next) => {
    next();
  },
  addMeeting: (req, res, next) => {
    next();
  }
};

module.exports = meetingController;
