using 201 for created entities in etapi

This commit is contained in:
zadam
2022-01-12 21:14:12 +01:00
parent ce046b2e20
commit 2248d98cc7
10 changed files with 67 additions and 56 deletions

View File

@@ -22,10 +22,10 @@ function register(router) {
'prefix': [v.isString],
'isExpanded': [v.notNull, v.isBoolean]
};
eu.route(router, 'post' ,'/etapi/branches', (req, res, next) => {
const params = {};
eu.validateAndPatch(params, req.body, ALLOWED_PROPERTIES_FOR_CREATE_BRANCH);
const existing = becca.getBranchFromChildAndParent(params.noteId, params.parentNoteId);
@@ -33,15 +33,16 @@ function register(router) {
if (existing) {
existing.notePosition = params.notePosition;
existing.prefix = params.prefix;
existing.isExpanded = params.isExpanded;
existing.save();
return res.json(mappers.mapBranchToPojo(existing));
return res.status(200).json(mappers.mapBranchToPojo(existing));
}
try {
const branch = new Branch(params).save();
res.json(mappers.mapBranchToPojo(branch));
res.status(201).json(mappers.mapBranchToPojo(branch));
}
catch (e) {
throw new eu.EtapiError(400, eu.GENERIC_CODE, e.message);