depurating picto expression update

parent 34168770
Showing with 15 additions and 27 deletions
...@@ -218,49 +218,37 @@ module.exports = { ...@@ -218,49 +218,37 @@ module.exports = {
change_exp: function (req, res) { change_exp: function (req, res) {
var params = req.params.all(); var params = req.params.all();
if (params.lang && params.text) { if (!params.lang || !params.text)
PictoExp.findOne({ id: params.picto, lang: params.lang }).then(function (pictoExpression) { return res.badRequest();
PictoExp.findOne({ id: params.picto, lang: params.lang })
.then(function (pictoExpression) {
if (!pictoExpression) { if (!pictoExpression) {
Picto.findOne({ id: params.picto }).then(function (picto) { Picto.findOne({ id: params.picto }).then(function (picto) {
if (!picto) { if (!picto)
res.badRequest(); return res.badRequest('Error: Picto not found');
throw new Error('Picto not found');
}
PictoExp.create({ PictoExp.create({
lang: params.lang, lang: params.lang,
text: params.text, text: params.text,
picto: picto.id picto: picto.id
}).then(function (newPictoExpression) { }).then(function (newPictoExpression) {
if (newPictoExpression) { if (!newPictoExpression)
res.ok(newPictoExpression); throw new Error("Could not create picto expression");
} else { return res.ok(newPictoExpression);
res.serverError();
}
})
.catch(function () {
res.serverError();
}); });
})
.catch(function () {
res.serverError();
}); });
} else { } else {
pictoExpression.text = params.text; pictoExpression.text = params.text;
pictoExpression.save(function (error) { pictoExpression.save(function (error) {
if (error) { if (error)
res.serverError(); throw new Error("Could not save expression");
} else { return res.ok(pictoExpression);
res.ok(pictoExpression);
}
}); });
} }
}) })
.catch(function () { .catch(function (err) {
res.serverError(); return res.serverError("Error from server: " + err);
}); });
} else {
res.badRequest();
}
}, },
/** /**
......
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