diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.js index c8e380a40..2a7a42cba 100644 --- a/src/public/app/widgets/note_attributes.js +++ b/src/public/app/widgets/note_attributes.js @@ -278,7 +278,7 @@ export default class NoteAttributesWidget extends TabAwareWidget { const attributes = this.parseAttributes(); if (attributes) { - await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId); + await server.put(`notes/${this.noteId}/attributes`, attributes, this.componentId); } } diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index ca82f99a4..a7246d08a 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -83,7 +83,7 @@ function deleteNoteAttribute(req) { } } -function updateNoteAttributes2(req) { +function updateNoteAttributes(req) { const noteId = req.params.noteId; const incomingAttributes = req.body; @@ -149,69 +149,6 @@ function updateNoteAttributes2(req) { } } -function updateNoteAttributes(req) { - const noteId = req.params.noteId; - const attributes = req.body; - - for (const attribute of attributes) { - let attributeEntity; - - if (attribute.attributeId) { - attributeEntity = repository.getAttribute(attribute.attributeId); - - if (attributeEntity.noteId !== noteId) { - return [400, `Attribute ${attributeEntity.noteId} is not owned by ${noteId}`]; - } - - if (attribute.type !== attributeEntity.type - || attribute.name !== attributeEntity.name - || (attribute.type === 'relation' && attribute.value !== attributeEntity.value) - || attribute.isInheritable !== attributeEntity.isInheritable) { - - if (attribute.type !== 'relation' || !!attribute.value.trim()) { - const newAttribute = attributeEntity.createClone(attribute.type, attribute.name, attribute.value, attribute.isInheritable); - newAttribute.save(); - } - - attributeEntity.isDeleted = true; - attributeEntity.save(); - - continue; - } - } - else { - // if it was "created" and then immediatelly deleted, we just don't create it at all - if (attribute.isDeleted) { - continue; - } - - attributeEntity = new Attribute(); - attributeEntity.noteId = noteId; - } - - attributeEntity.type = attribute.type; - attributeEntity.name = attribute.name; - attributeEntity.position = attribute.position; - attributeEntity.isInheritable = attribute.isInheritable; - attributeEntity.isDeleted = attribute.isDeleted; - - if (attributeEntity.type === 'relation' && !attribute.value.trim()) { - // relation should never have empty target - attributeEntity.isDeleted = true; - } - else { - attributeEntity.value = attribute.value; - } - - attributeEntity.save(); - } - - const note = repository.getNote(noteId); - note.invalidateAttributeCache(); - - return note.getAttributes(); -} - function getAttributeNames(req) { const type = req.query.type; const query = req.query.query; @@ -260,7 +197,6 @@ function deleteRelation(req) { module.exports = { updateNoteAttributes, - updateNoteAttributes2, updateNoteAttribute, deleteNoteAttribute, getAttributeNames, diff --git a/src/routes/routes.js b/src/routes/routes.js index ee6653930..e7c5d832c 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -174,7 +174,6 @@ function register(app) { apiRoute(GET, '/api/notes/:noteId/attributes', attributesRoute.getEffectiveNoteAttributes); apiRoute(PUT, '/api/notes/:noteId/attributes', attributesRoute.updateNoteAttributes); - apiRoute(PUT, '/api/notes/:noteId/attributes2', attributesRoute.updateNoteAttributes2); apiRoute(PUT, '/api/notes/:noteId/attribute', attributesRoute.updateNoteAttribute); apiRoute(PUT, '/api/notes/:noteId/relations/:name/to/:targetNoteId', attributesRoute.createRelation); apiRoute(DELETE, '/api/notes/:noteId/relations/:name/to/:targetNoteId', attributesRoute.deleteRelation);