mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
HistoryService: Add JSDocs for all methods
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
cc50a1f49c
commit
df2f14ffbf
1 changed files with 49 additions and 1 deletions
|
@ -29,6 +29,12 @@ export class HistoryService {
|
||||||
this.logger.setContext(HistoryService.name);
|
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[]> {
|
async getEntriesByUser(user: User): Promise<HistoryEntry[]> {
|
||||||
return await this.historyEntryRepository.find({
|
return await this.historyEntryRepository.find({
|
||||||
where: { user: user },
|
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,
|
noteIdOrAlias: string,
|
||||||
user: User,
|
user: User,
|
||||||
): Promise<HistoryEntry> {
|
): Promise<HistoryEntry> {
|
||||||
|
@ -44,6 +58,13 @@ export class HistoryService {
|
||||||
return await this.getEntryByNote(note, user);
|
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> {
|
private async getEntryByNote(note: Note, user: User): Promise<HistoryEntry> {
|
||||||
return await this.historyEntryRepository.findOne({
|
return await this.historyEntryRepository.findOne({
|
||||||
where: {
|
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(
|
async createOrUpdateHistoryEntry(
|
||||||
note: Note,
|
note: Note,
|
||||||
user: User,
|
user: User,
|
||||||
|
@ -67,6 +95,14 @@ export class HistoryService {
|
||||||
return await this.historyEntryRepository.save(entry);
|
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(
|
async updateHistoryEntry(
|
||||||
noteIdOrAlias: string,
|
noteIdOrAlias: string,
|
||||||
user: User,
|
user: User,
|
||||||
|
@ -82,6 +118,13 @@ export class HistoryService {
|
||||||
return await this.historyEntryRepository.save(entry);
|
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> {
|
async deleteHistoryEntry(noteIdOrAlias: string, user: User): Promise<void> {
|
||||||
const entry = await this.getEntryByNoteIdOrAlias(noteIdOrAlias, user);
|
const entry = await this.getEntryByNoteIdOrAlias(noteIdOrAlias, user);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
@ -93,6 +136,11 @@ export class HistoryService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build HistoryEntryDto from a history entry.
|
||||||
|
* @param {HistoryEntry} entry - the history entry to use
|
||||||
|
* @return {HistoryEntryDto} the built HistoryEntryDto
|
||||||
|
*/
|
||||||
toHistoryEntryDto(entry: HistoryEntry): HistoryEntryDto {
|
toHistoryEntryDto(entry: HistoryEntry): HistoryEntryDto {
|
||||||
return {
|
return {
|
||||||
identifier: entry.note.alias ? entry.note.alias : entry.note.id,
|
identifier: entry.note.alias ? entry.note.alias : entry.note.id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue