const User = require('../models/User.js');

const getUser = async (req, res) => {
  console.log('getUser', req.params.username);
  res.send('getUser');
};

const saveJob = async (req, res) => {
  const { jobId } = req.params;

  if (!req.user) return res.status(401).send();

  const { username } = req.user;

  const user = await User.findOne({ username });
  const jobIndex = user.savedJobs.indexOf(jobId);

  !~jobIndex ? user.savedJobs.push(jobId) : user.savedJobs.splice(jobIndex, 1);

  const result = await user.save();
  // Temp status for testing
  const status = ~result.savedJobs.indexOf(jobId) ? 'saved to' : 'removed from';
  res.send(`Job ${jobId} ${status} ${username} profile.`);
};
};

module.exports = {
  getUser,
  saveJob,
};

@@ -691,16 +691,171 @@
 e.%60);%0A%7D;
+%0A%0Aconst selectJobAction = (req, res) =%3E %7B%0A  // Use req.query.hasOwnProperty() to select different method%0A  // Default to 'save'%0A  return saveJob(req, res);
 %0A%7D;%0A%0Amod

Create selectJobAction controller