When creating a schema using Joi and expecting a JSON response that matches the schema upon POSTing, an issue arises. The dilemma is having to include a parent element (in this case "data:") in the JSON response, although ideally the schema's attributes should stand alone without it. However, attempting to exclude the parent results in Object.assign(value) not functioning properly. Any suggestions on how to address this?
.post((req,res,next) => {
let data = req.body;
Joi.validate(data, schema, (err, value) => {
res.json({
data: Object.assign(value)
});
});
})
Expected Output:
{
"title": "dasdawdasfasd",
"textshort": "wasser",
"textlong": "",
"imgwidth": null,
"imgheight": null,
"imgsrc": "",
"views": 0,
"keywords": []
}
Actual Output:
{
"data": {
"title": "dasdawdasfasd",
"textshort": "wasser",
"textlong": "",
"imgwidth": null,
"imgheight": null,
"imgsrc": "",
"views": 0,
"keywords": []
}
}