mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-02-17 01:41:45 +00:00
HistoryService: Add JSDocs for all methods
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
66e2340009
commit
6ed686e657
1 changed files with 49 additions and 1 deletions
|
@ -29,6 +29,12 @@ export class HistoryService {
|
|||
this.logger.setContext(HistoryService.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Get all entries of a user
|
||||
* @param {User} user - the user the entries should be from
|
||||
* @return {HistoryEntry[]} an array of history entries of the specified user
|
||||
*/
|
||||
async getEntriesByUser(user: User): Promise<HistoryEntry[]> {
|
||||
return await this.historyEntryRepository.find({
|
||||
where: { user: user },
|
||||
|
@ -36,7 +42,15 @@ export class HistoryService {
|
|||
});
|
||||
}
|
||||
|
||||
private async getEntryByNoteIdOrAlias(
|
||||
/**
|
||||
* @async
|
||||
* Get a history entry by the user and note, which is specified via id or alias
|
||||
* @param {string} noteIdOrAlias - the id or alias specifying the note
|
||||
* @param {User} user - the user that the note belongs to
|
||||
* @throws {NotInDBError} the specified note does not exist
|
||||
* @return {HistoryEntry} the requested history entry
|
||||
*/
|
||||
async getEntryByNoteIdOrAlias(
|
||||
noteIdOrAlias: string,
|
||||
user: User,
|
||||
): Promise<HistoryEntry> {
|
||||
|
@ -44,6 +58,13 @@ export class HistoryService {
|
|||
return await this.getEntryByNote(note, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Get a history entry by the user and note
|
||||
* @param {Note} note - the note that the history entry belongs to
|
||||
* @param {User} user - the user that the history entry belongs to
|
||||
* @return {HistoryEntry} the requested history entry
|
||||
*/
|
||||
private async getEntryByNote(note: Note, user: User): Promise<HistoryEntry> {
|
||||
return await this.historyEntryRepository.findOne({
|
||||
where: {
|
||||
|
@ -54,6 +75,13 @@ export class HistoryService {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Create or update a history entry by the user and note. If the entry is merely updated the updatedAt date is set to the current date.
|
||||
* @param {Note} note - the note that the history entry belongs to
|
||||
* @param {User} user - the user that the history entry belongs to
|
||||
* @return {HistoryEntry} the requested history entry
|
||||
*/
|
||||
async createOrUpdateHistoryEntry(
|
||||
note: Note,
|
||||
user: User,
|
||||
|
@ -67,6 +95,14 @@ export class HistoryService {
|
|||
return await this.historyEntryRepository.save(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Update a history entry identified by the user and a note id or alias
|
||||
* @param {string} noteIdOrAlias - the note that the history entry belongs to
|
||||
* @param {User} user - the user that the history entry belongs to
|
||||
* @param {HistoryEntryUpdateDto} updateDto - the change that should be applied to the history entry
|
||||
* @return {HistoryEntry} the requested history entry
|
||||
*/
|
||||
async updateHistoryEntry(
|
||||
noteIdOrAlias: string,
|
||||
user: User,
|
||||
|
@ -82,6 +118,13 @@ export class HistoryService {
|
|||
return await this.historyEntryRepository.save(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Delete the history entry identified by the user and a note id or alias
|
||||
* @param {string} noteIdOrAlias - the note that the history entry belongs to
|
||||
* @param {User} user - the user that the history entry belongs to
|
||||
* @throws {NotInDBError} the specified history entry does not exist
|
||||
*/
|
||||
async deleteHistoryEntry(noteIdOrAlias: string, user: User): Promise<void> {
|
||||
const entry = await this.getEntryByNoteIdOrAlias(noteIdOrAlias, user);
|
||||
if (!entry) {
|
||||
|
@ -93,6 +136,11 @@ export class HistoryService {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build HistoryEntryDto from a history entry.
|
||||
* @param {HistoryEntry} entry - the history entry to use
|
||||
* @return {HistoryEntryDto} the built HistoryEntryDto
|
||||
*/
|
||||
toHistoryEntryDto(entry: HistoryEntry): HistoryEntryDto {
|
||||
return {
|
||||
identifier: entry.note.alias ? entry.note.alias : entry.note.id,
|
||||
|
|
Loading…
Reference in a new issue