mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -04:00
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:
parent
170f4f6759
commit
f63a2b79b7
4 changed files with 147 additions and 0 deletions
|
@ -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: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue