From c2b6c6fe497731ef41881150e391ae2a78adc5e9 Mon Sep 17 00:00:00 2001 From: Yannick Bungers Date: Sat, 30 Jan 2021 18:09:00 +0100 Subject: [PATCH] Reformat code by yarn format Signed-off-by: Yannick Bungers --- src/api/public/me/me.controller.ts | 4 +- src/api/public/media/media.controller.ts | 9 ++-- .../monitoring/monitoring.controller.ts | 2 +- src/api/public/notes/notes.controller.ts | 51 ++++++++++--------- src/media/media-upload-url.dto.ts | 4 +- src/media/media.service.ts | 8 ++- src/notes/notes.service.ts | 51 ++++++++++--------- src/revisions/revisions.service.ts | 6 +-- 8 files changed, 73 insertions(+), 62 deletions(-) diff --git a/src/api/public/me/me.controller.ts b/src/api/public/me/me.controller.ts index 6d35c9917..4bbf8ccdb 100644 --- a/src/api/public/me/me.controller.ts +++ b/src/api/public/me/me.controller.ts @@ -79,9 +79,9 @@ export class MeController { @UseGuards(TokenAuthGuard) @Get('notes') async getMyNotes(@Request() req): Promise { - const notes = await this.notesService.getUserNotes(req.user) + const notes = await this.notesService.getUserNotes(req.user); return Promise.all( - notes.map(note => this.notesService.toNoteMetadataDto(note)) + notes.map((note) => this.notesService.toNoteMetadataDto(note)), ); } } diff --git a/src/api/public/media/media.controller.ts b/src/api/public/media/media.controller.ts index 0234c42db..c1c211063 100644 --- a/src/api/public/media/media.controller.ts +++ b/src/api/public/media/media.controller.ts @@ -48,7 +48,7 @@ export class MediaController { @Request() req, @UploadedFile() file: MulterFile, @Headers('HedgeDoc-Note') noteId: string, - ) : Promise { + ): Promise { const username = req.user.userName; this.logger.debug( `Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`, @@ -60,7 +60,7 @@ export class MediaController { username, noteId, ); - return this.mediaService.toMediaUploadUrlDto(url) + return this.mediaService.toMediaUploadUrlDto(url); } catch (e) { if (e instanceof ClientError || e instanceof NotInDBError) { throw new BadRequestException(e.message); @@ -71,7 +71,10 @@ export class MediaController { @UseGuards(TokenAuthGuard) @Delete(':filename') - async deleteMedia(@Request() req, @Param('filename') filename: string) : Promise { + async deleteMedia( + @Request() req, + @Param('filename') filename: string, + ): Promise { const username = req.user.userName; try { await this.mediaService.deleteFile(filename, username); diff --git a/src/api/public/monitoring/monitoring.controller.ts b/src/api/public/monitoring/monitoring.controller.ts index c7cde2193..d90b81117 100644 --- a/src/api/public/monitoring/monitoring.controller.ts +++ b/src/api/public/monitoring/monitoring.controller.ts @@ -17,7 +17,7 @@ export class MonitoringController { @UseGuards(TokenAuthGuard) @Get() - getStatus() : Promise { + getStatus(): Promise { // TODO: toServerStatusDto. return this.monitoringService.getServerStatus(); } diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index 159e58ef9..4478356d5 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -19,7 +19,10 @@ import { } from '@nestjs/common'; import { NotInDBError } from '../../../errors/errors'; import { ConsoleLoggerService } from '../../../logger/console-logger.service'; -import { NotePermissionsDto, NotePermissionsUpdateDto } from '../../../notes/note-permissions.dto'; +import { + NotePermissionsDto, + NotePermissionsUpdateDto, +} from '../../../notes/note-permissions.dto'; import { NotesService } from '../../../notes/notes.service'; import { RevisionsService } from '../../../revisions/revisions.service'; import { MarkdownBody } from '../../utils/markdownbody-decorator'; @@ -43,11 +46,14 @@ export class NotesController { @UseGuards(TokenAuthGuard) @Post() - async createNote(@Request() req, @MarkdownBody() text: string): Promise { + async createNote( + @Request() req, + @MarkdownBody() text: string, + ): Promise { // ToDo: provide user for createNoteDto this.logger.debug('Got raw markdown:\n' + text); return this.noteService.toNoteDto( - await this.noteService.createNote(text, undefined, req.user) + await this.noteService.createNote(text, undefined, req.user), ); } @@ -61,17 +67,20 @@ export class NotesController { // ToDo: check if user is allowed to view this note this.logger.debug('Got raw markdown:\n' + text); return this.noteService.toNoteDto( - await this.noteService.createNote(text, noteAlias, req.user) + await this.noteService.createNote(text, noteAlias, req.user), ); } @UseGuards(TokenAuthGuard) @Get(':noteIdOrAlias') - async getNote(@Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string) : Promise { + async getNote( + @Request() req, + @Param('noteIdOrAlias') noteIdOrAlias: string, + ): Promise { // ToDo: check if user is allowed to view this note try { return this.noteService.toNoteDto( - await this.noteService.getNoteByIdOrAlias(noteIdOrAlias) + await this.noteService.getNoteByIdOrAlias(noteIdOrAlias), ); } catch (e) { if (e instanceof NotInDBError) { @@ -107,12 +116,12 @@ export class NotesController { @Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string, @MarkdownBody() text: string, - ) : Promise { + ): Promise { // ToDo: check if user is allowed to change this note this.logger.debug('Got raw markdown:\n' + text); try { return this.noteService.toNoteDto( - await this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, text) + await this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, text), ); } catch (e) { if (e instanceof NotInDBError) { @@ -128,7 +137,7 @@ export class NotesController { async getNoteContent( @Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string, - ) : Promise { + ): Promise { // ToDo: check if user is allowed to view this notes content try { return await this.noteService.getNoteContent(noteIdOrAlias); @@ -145,11 +154,11 @@ export class NotesController { async getNoteMetadata( @Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string, - ) : Promise { + ): Promise { // ToDo: check if user is allowed to view this notes metadata try { return this.noteService.toNoteMetadataDto( - await this.noteService.getNoteByIdOrAlias(noteIdOrAlias) + await this.noteService.getNoteByIdOrAlias(noteIdOrAlias), ); } catch (e) { if (e instanceof NotInDBError) { @@ -165,14 +174,11 @@ export class NotesController { @Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string, @Body() updateDto: NotePermissionsUpdateDto, - ) : Promise { + ): Promise { // ToDo: check if user is allowed to view this notes permissions try { return this.noteService.toNotePermissionsDto( - await this.noteService.updateNotePermissions( - noteIdOrAlias, - updateDto, - ) + await this.noteService.updateNotePermissions(noteIdOrAlias, updateDto), ); } catch (e) { if (e instanceof NotInDBError) { @@ -187,14 +193,16 @@ export class NotesController { async getNoteRevisions( @Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string, - ) : Promise { + ): Promise { // ToDo: check if user is allowed to view this notes revisions try { const revisions = await this.revisionsService.getAllRevisions( noteIdOrAlias, ); return Promise.all( - revisions.map(revision => this.revisionsService.toRevisionMetadataDto(revision)) + revisions.map((revision) => + this.revisionsService.toRevisionMetadataDto(revision), + ), ); } catch (e) { if (e instanceof NotInDBError) { @@ -210,14 +218,11 @@ export class NotesController { @Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string, @Param('revisionId') revisionId: number, - ) : Promise { + ): Promise { // ToDo: check if user is allowed to view this notes revision try { return this.revisionsService.toRevisionDto( - await this.revisionsService.getRevision( - noteIdOrAlias, - revisionId, - ) + await this.revisionsService.getRevision(noteIdOrAlias, revisionId), ); } catch (e) { if (e instanceof NotInDBError) { diff --git a/src/media/media-upload-url.dto.ts b/src/media/media-upload-url.dto.ts index c4b869894..9e9c9296c 100644 --- a/src/media/media-upload-url.dto.ts +++ b/src/media/media-upload-url.dto.ts @@ -4,11 +4,9 @@ * SPDX-License-Identifier: AGPL-3.0-only */ - - import { IsString } from 'class-validator'; export class MediaUploadUrlDto { @IsString() - link: string + link: string; } diff --git a/src/media/media.service.ts b/src/media/media.service.ts index 4714281c4..b22aa8aab 100644 --- a/src/media/media.service.ts +++ b/src/media/media.service.ts @@ -59,7 +59,11 @@ export class MediaService { return allowedTypes.includes(mimeType); } - public async saveFile(fileBuffer: Buffer, username: string, noteId: string): Promise { + public async saveFile( + fileBuffer: Buffer, + username: string, + noteId: string, + ): Promise { this.logger.debug( `Saving file for note '${noteId}' and user '${username}'`, 'saveFile', @@ -137,6 +141,6 @@ export class MediaService { toMediaUploadUrlDto(url: string): MediaUploadUrlDto { return { link: url, - } + }; } } diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index b810246f4..0e3998987 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -41,7 +41,7 @@ export class NotesService { { id: 'foobar-barfoo', alias: null, - shortid: "abc", + shortid: 'abc', owner: user, description: 'Very descriptive text.', userPermissions: [], @@ -125,7 +125,10 @@ export class NotesService { return await this.noteRepository.remove(note); } - async updateNoteByIdOrAlias(noteIdOrAlias: string, noteContent: string): Promise { + async updateNoteByIdOrAlias( + noteIdOrAlias: string, + noteContent: string, + ): Promise { const note = await this.getNoteByIdOrAlias(noteIdOrAlias); const revisions = await note.revisions; //TODO: Calculate patch @@ -140,27 +143,27 @@ export class NotesService { ): Note { this.logger.warn('Using hardcoded data!'); return { - id: 'foobar-barfoo', - alias: null, - shortid: "abc", - owner: { - authTokens: [], - createdAt: new Date(), - displayName: 'hardcoded', - id: '1', - identities: [], - ownedNotes: [], - updatedAt: new Date(), - userName: 'Testy', - }, - description: 'Very descriptive text.', - userPermissions: [], - groupPermissions: [], - tags: [], - revisions: Promise.resolve([]), - authorColors: [], - title: 'Title!', - viewcount: 42, + id: 'foobar-barfoo', + alias: null, + shortid: 'abc', + owner: { + authTokens: [], + createdAt: new Date(), + displayName: 'hardcoded', + id: '1', + identities: [], + ownedNotes: [], + updatedAt: new Date(), + userName: 'Testy', + }, + description: 'Very descriptive text.', + userPermissions: [], + groupPermissions: [], + tags: [], + revisions: Promise.resolve([]), + authorColors: [], + title: 'Title!', + viewcount: 42, }; } @@ -180,7 +183,7 @@ export class NotesService { group: noteGroupPermission.group, canEdit: noteGroupPermission.canEdit, })), - } + }; } async toNoteMetadataDto(note: Note): Promise { diff --git a/src/revisions/revisions.service.ts b/src/revisions/revisions.service.ts index 5052b0dc1..a3735337d 100644 --- a/src/revisions/revisions.service.ts +++ b/src/revisions/revisions.service.ts @@ -24,9 +24,7 @@ export class RevisionsService { this.logger.setContext(RevisionsService.name); } - async getAllRevisions( - noteIdOrAlias: string, - ): Promise { + async getAllRevisions(noteIdOrAlias: string): Promise { const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias); return await this.revisionRepository.find({ where: { @@ -88,7 +86,7 @@ export class RevisionsService { }; } - createRevision(content: string) : Revision { + createRevision(content: string): Revision { // TODO: Add previous revision // TODO: Calculate patch // TODO: Save metadata