Add new API to purge note history #1064

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Combine the describe block

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Fix naming

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Rename purgeRevision to purgeRevisions

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Fix notes e2e test description

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Add yarn.lock

Fix lint and format

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>
This commit is contained in:
Abhilasha Sinha 2021-08-30 05:37:35 +05:30 committed by David Mehren
parent 170f4f6759
commit f63a2b79b7
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
4 changed files with 147 additions and 0 deletions

View file

@ -34,6 +34,27 @@ export class RevisionsService {
});
}
/**
* @async
* Purge revision history of a note.
* @param {Note} note - the note to purge the history
* @return {Revision[]} an array of purged revisions
*/
async purgeRevisions(note: Note): Promise<Revision[]> {
const revisions = await this.revisionRepository.find({
where: {
note: note,
},
});
const latestRevison = await this.getLatestRevision(note);
// get all revisions except the latest
const oldRevisions = revisions.filter(
(item) => item.id !== latestRevison.id,
);
// delete the old revisions
return await this.revisionRepository.remove(oldRevisions);
}
async getRevision(note: Note, revisionId: number): Promise<Revision> {
const revision = await this.revisionRepository.findOne({
where: {