Skip to content

Commit

Permalink
feat: add updating revision patch when removing old revision
Browse files Browse the repository at this point in the history
Signed-off-by: yamashush <38120991+yamashush@users.noreply.github.com>
  • Loading branch information
yamashush committed May 5, 2024
1 parent fc1ce37 commit 2106f68
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions backend/src/revisions/revisions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,28 @@ export class RevisionsService {
new Date(revision.createdAt).getTime() <=
currentTime - revisionRetentionDays * 24 * 60 * 60 * 1000,
);
const remainedRevisions = revisions.filter((val) => !oldRevisions.includes(val))

if (!oldRevisions.length) {
continue;

} else if (oldRevisions.length == revisions.length - 1 ){
const beUpdatedRevision = revisions.slice(-1)[0]
beUpdatedRevision.patch = createPatch(
note.publicId,
'', // donnt exist older revision
beUpdatedRevision.content,
);
await this.revisionRepository.save(beUpdatedRevision);

} else {
const beUpdatedRevision = remainedRevisions.slice(0)[0]
beUpdatedRevision.patch = createPatch(
note.publicId,
oldRevisions.slice(-1)[0].content,
revisions[1].content,
);
await this.revisionRepository.save(beUpdatedRevision);
}

await this.revisionRepository.remove(oldRevisions);
Expand Down

0 comments on commit 2106f68

Please sign in to comment.