depurating picto expression update

parent 34168770
Showing with 30 additions and 42 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();
if (!pictoExpression) {
Picto.findOne({ id: params.picto }).then(function (picto) { PictoExp.findOne({ id: params.picto, lang: params.lang })
if (!picto) { .then(function (pictoExpression) {
res.badRequest(); if (!pictoExpression) {
throw new Error('Picto not found'); Picto.findOne({ id: params.picto }).then(function (picto) {
} if (!picto)
PictoExp.create({ return res.badRequest('Error: Picto not found');
lang: params.lang, PictoExp.create({
text: params.text, lang: params.lang,
picto: picto.id text: params.text,
}).then(function (newPictoExpression) { picto: picto.id
if (newPictoExpression) { }).then(function (newPictoExpression) {
res.ok(newPictoExpression); if (!newPictoExpression)
} else { throw new Error("Could not create picto expression");
res.serverError(); return res.ok(newPictoExpression);
}
})
.catch(function () {
res.serverError();
});
})
.catch(function () {
res.serverError();
});
} else {
pictoExpression.text = params.text;
pictoExpression.save(function (error) {
if (error) {
res.serverError();
} else {
res.ok(pictoExpression);
}
}); });
} });
}) } else {
.catch(function () { pictoExpression.text = params.text;
res.serverError(); pictoExpression.save(function (error) {
}); if (error)
} else { throw new Error("Could not save expression");
res.badRequest(); return res.ok(pictoExpression);
} });
}
})
.catch(function (err) {
return res.serverError("Error from server: " + err);
});
}, },
/** /**
......
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