diff --git a/.eslintrc.js b/.eslintrc.js index cf6e6e7fd..8dd058c86 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,5 +27,7 @@ module.exports = { { argsIgnorePattern: '^_+$' }, ], '@typescript-eslint/explicit-module-boundary-types': 'off', + 'no-return-await': 'off', + '@typescript-eslint/return-await': ['error', 'always'], }, }; diff --git a/src/api/private/tokens/tokens.controller.ts b/src/api/private/tokens/tokens.controller.ts index 651982b13..cb44b93a8 100644 --- a/src/api/private/tokens/tokens.controller.ts +++ b/src/api/private/tokens/tokens.controller.ts @@ -44,12 +44,16 @@ export class TokensController { @Body('validUntil') validUntil: TimestampMillis, ): Promise { // ToDo: Get real userName - return this.authService.createTokenForUser('hardcoded', label, validUntil); + return await this.authService.createTokenForUser( + 'hardcoded', + label, + validUntil, + ); } @Delete('/:keyId') @HttpCode(204) async deleteToken(@Param('keyId') keyId: string) { - return this.authService.removeToken(keyId); + return await this.authService.removeToken(keyId); } } diff --git a/src/api/public/me/me.controller.ts b/src/api/public/me/me.controller.ts index 89e8eef28..dc46d647d 100644 --- a/src/api/public/me/me.controller.ts +++ b/src/api/public/me/me.controller.ts @@ -53,7 +53,7 @@ export class MeController { @Get('history') async getUserHistory(@Request() req): Promise { const foundEntries = await this.historyService.getEntriesByUser(req.user); - return Promise.all( + return await Promise.all( foundEntries.map( async (entry) => await this.historyService.toHistoryEntryDto(entry), ), @@ -69,7 +69,7 @@ export class MeController { ): Promise { // ToDo: Check if user is allowed to pin this history entry try { - return this.historyService.toHistoryEntryDto( + return await this.historyService.toHistoryEntryDto( await this.historyService.updateHistoryEntry( note, req.user, @@ -103,7 +103,7 @@ export class MeController { @Get('notes') async getMyNotes(@Request() req): Promise { const notes = await this.notesService.getUserNotes(req.user); - return Promise.all( + return await Promise.all( notes.map((note) => this.notesService.toNoteMetadataDto(note)), ); } diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index e7739529b..e94cb3a57 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -67,7 +67,7 @@ export class NotesController { throw new UnauthorizedException('Creating note denied!'); } this.logger.debug('Got raw markdown:\n' + text); - return this.noteService.toNoteDto( + return await this.noteService.toNoteDto( await this.noteService.createNote(text, undefined, req.user), ); } @@ -91,7 +91,7 @@ export class NotesController { throw new UnauthorizedException('Reading note denied!'); } await this.historyService.createOrUpdateHistoryEntry(note, req.user); - return this.noteService.toNoteDto(note); + return await this.noteService.toNoteDto(note); } @UseGuards(TokenAuthGuard) @@ -106,7 +106,7 @@ export class NotesController { } this.logger.debug('Got raw markdown:\n' + text, 'createNamedNote'); try { - return this.noteService.toNoteDto( + return await this.noteService.toNoteDto( await this.noteService.createNote(text, noteAlias, req.user), ); } catch (e) { @@ -153,7 +153,7 @@ export class NotesController { throw new UnauthorizedException('Updating note denied!'); } this.logger.debug('Got raw markdown:\n' + text, 'updateNote'); - return this.noteService.toNoteDto( + return await this.noteService.toNoteDto( await this.noteService.updateNote(note, text), ); } catch (e) { @@ -196,7 +196,7 @@ export class NotesController { if (!this.permissionsService.mayRead(req.user, note)) { throw new UnauthorizedException('Reading note denied!'); } - return this.noteService.toNoteMetadataDto(note); + return await this.noteService.toNoteMetadataDto(note); } catch (e) { if (e instanceof NotInDBError) { throw new NotFoundException(e.message); @@ -220,7 +220,7 @@ export class NotesController { if (!this.permissionsService.isOwner(req.user, note)) { throw new UnauthorizedException('Updating note denied!'); } - return this.noteService.toNotePermissionsDto( + return await this.noteService.toNotePermissionsDto( await this.noteService.updateNotePermissions(note, updateDto), ); } catch (e) { @@ -243,7 +243,7 @@ export class NotesController { throw new UnauthorizedException('Reading note denied!'); } const revisions = await this.revisionsService.getAllRevisions(note); - return Promise.all( + return await Promise.all( revisions.map((revision) => this.revisionsService.toRevisionMetadataDto(revision), ), diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 25aaaec12..ed3b36c43 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -49,17 +49,17 @@ export class AuthService { } const accessToken = await this.getAuthTokenAndValidate(keyId, secret); await this.setLastUsedToken(keyId); - return this.usersService.getUserByUsername(accessToken.user.userName); + return await this.usersService.getUserByUsername(accessToken.user.userName); } async hashPassword(cleartext: string): Promise { // hash the password with bcrypt and 2^12 iterations // this was decided on the basis of https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#bcrypt - return hash(cleartext, 12); + return await hash(cleartext, 12); } async checkPassword(cleartext: string, password: string): Promise { - return compare(cleartext, password); + return await compare(cleartext, password); } async randomString(length: number): Promise { @@ -209,13 +209,13 @@ export class AuthService { // Delete all non valid tokens every sunday on 3:00 AM @Cron('0 0 3 * * 0') async handleCron() { - return this.removeInvalidTokens(); + return await this.removeInvalidTokens(); } // Delete all non valid tokens 5 sec after startup @Timeout(5000) async handleTimeout() { - return this.removeInvalidTokens(); + return await this.removeInvalidTokens(); } async removeInvalidTokens() { diff --git a/src/history/history.service.ts b/src/history/history.service.ts index 84583220e..1d3d908ac 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -79,7 +79,7 @@ export class HistoryService { ); } entry.pinStatus = updateDto.pinStatus; - return this.historyEntryRepository.save(entry); + return await this.historyEntryRepository.save(entry); } async deleteHistoryEntry(noteIdOrAlias: string, user: User): Promise { diff --git a/src/media/backends/filesystem-backend.ts b/src/media/backends/filesystem-backend.ts index cefc088c3..5978b7903 100644 --- a/src/media/backends/filesystem-backend.ts +++ b/src/media/backends/filesystem-backend.ts @@ -46,7 +46,7 @@ export class FilesystemBackend implements MediaBackend { async deleteFile(fileName: string, _: BackendData): Promise { const filePath = this.getFilePath(fileName); try { - return fs.unlink(filePath); + return await fs.unlink(filePath); } catch (e) { this.logger.error(e.message, e.stack, 'deleteFile'); throw new MediaBackendError(`Could not delete '${filePath}'`); diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 5b99e6f78..d278297a2 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -202,7 +202,7 @@ export class NotesService { //TODO: Calculate patch revisions.push(Revision.create(noteContent, noteContent)); note.revisions = Promise.resolve(revisions); - return this.noteRepository.save(note); + return await this.noteRepository.save(note); } /**