solved issue with supervisor linking

parent dfef2f37
...@@ -551,18 +551,20 @@ module.exports = { ...@@ -551,18 +551,20 @@ module.exports = {
* *
*/ */
link_supervisor: function (req, res) { link_supervisor: function (req, res) {
if (!req.params.id_off || !req.params.id_sup) var params = req.allParams();
if (!params.id_off || !params.id_sup)
return res.badRequest(); return res.badRequest();
if (req.params.id_off == req.params.id_sup) if (params.id_off == params.id_sup)
return res.badRequest("Link to yourself is not allowed"); return res.badRequest("Link to yourself is not allowed");
// Check that both ids are valid // Check that both ids are valid
Supervisor.findOne(req.params.id_sup) Supervisor.findOne(params.id_sup)
.then((sup) => { .then((sup) => {
if (!sup) if (!sup)
throw new Error("Supervisor not found"); throw new Error("Supervisor not found");
return [sup, Supervisor.findOne(req.params.id_off)]; return [sup, Supervisor.findOne(params.id_off)];
}) })
.spread((sup, off) => { .spread((sup, off) => {
if (!off) if (!off)
...@@ -601,20 +603,22 @@ module.exports = { ...@@ -601,20 +603,22 @@ module.exports = {
* *
*/ */
unlink_supervisor: function (req, res) { unlink_supervisor: function (req, res) {
if (!req.params.id_off || !req.params.id_sup) var params = req.allParams();
if (!params.id_off || !params.id_sup)
return res.badRequest(); return res.badRequest();
// Check that both ids are valid // Check that both ids are valid
Supervisor.findOne(req.params.id_sup) Supervisor.findOne(params.id_sup)
.then((s) => { .then((s) => {
if (!s) if (!s)
throw new Error("Supervisor not found"); throw new Error("Supervisor not found");
return Supervisor.findOne(req.params.id_off); return Supervisor.findOne(params.id_off);
}) })
.then((s) => { .then((s) => {
if (!s) if (!s)
throw new Error("Supervisor not found"); throw new Error("Supervisor not found");
return SupOff.destroy({supervisor: req.params.id_sup, office: req.params.id_off}); return SupOff.destroy({supervisor: params.id_sup, office: params.id_off});
}) })
.then((sos) => { .then((sos) => {
if (!sos) if (!sos)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment