Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement note changes history #268

Closed
e11sy opened this issue Jul 13, 2024 · 1 comment
Closed

Implement note changes history #268

e11sy opened this issue Jul 13, 2024 · 1 comment

Comments

@e11sy
Copy link
Contributor

e11sy commented Jul 13, 2024

Problem

For now we can complitely grind all note (on web) just by highliting full note and pressing any character
We need to be able to check note content history and get back to the content that was actual some time ago

Solution

Add new table with this structure:

public.note_history {
  id: integer NOT NULL
  note_id: integer NOT NULL        -- `noteInternalId`
  user_id: integer
  updated_at: TIMESTAMP NOT NULL
  content: json
}

also create note_id index

Create routes

GET /note/:id/history

For getting all history records info of the specific note

GET /note/:id/history/:historyId

For getting content of the note history record

Create service methods

checkContentDifference()

  • On PATCH /note request, we should check that content changes are enough to save the new version of the content into history
  • For this we need to calculate total note content lengths and compare them
const noteContentLength = content.blocks.reduce((length, block) =>{
   length += JSON.stringify(block.data).length;

   return length;
}, 0);
  • The first content comes from the PATCH method, the second we take as the last saved content from the history of this note
  • If the length differs by more than N, then we add a new record with the content of the note into public.notes_history table and update the note in public.notes table

getNoteHistoryByNoteId()

In this method we should return only additional info of note history (id, user_id, updated_at) that info will be displayed in web part

getHistoryRecordById()

In this method we need to return full record with content (this method will be used for preview of the history record)

Create NoteHistoryRepository and NoteHistoryStorage

Here we must provide data for the correct operation of the service methods

@e11sy
Copy link
Contributor Author

e11sy commented Jul 25, 2024

solved in #269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant