Reformat code by yarn format

Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
Yannick Bungers 2021-01-30 18:09:00 +01:00 committed by David Mehren
parent 5920a1c72f
commit 22aaa956a7
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
8 changed files with 73 additions and 62 deletions

View file

@ -79,9 +79,9 @@ export class MeController {
@UseGuards(TokenAuthGuard)
@Get('notes')
async getMyNotes(@Request() req): Promise<NoteMetadataDto[]> {
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)),
);
}
}

View file

@ -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<void> {
async deleteMedia(
@Request() req,
@Param('filename') filename: string,
): Promise<void> {
const username = req.user.userName;
try {
await this.mediaService.deleteFile(filename, username);

View file

@ -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<NoteDto> {
async createNote(
@Request() req,
@MarkdownBody() text: string,
): Promise<NoteDto> {
// 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<NoteDto> {
async getNote(
@Request() req,
@Param('noteIdOrAlias') noteIdOrAlias: string,
): Promise<NoteDto> {
// 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) {
@ -112,7 +121,7 @@ export class NotesController {
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) {
@ -149,7 +158,7 @@ export class NotesController {
// 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) {
@ -169,10 +178,7 @@ export class NotesController {
// 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) {
@ -194,7 +200,9 @@ export class NotesController {
noteIdOrAlias,
);
return Promise.all(
revisions.map(revision => this.revisionsService.toRevisionMetadataDto(revision))
revisions.map((revision) =>
this.revisionsService.toRevisionMetadataDto(revision),
),
);
} catch (e) {
if (e instanceof NotInDBError) {
@ -214,10 +222,7 @@ export class NotesController {
// 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) {

View file

@ -4,11 +4,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { IsString } from 'class-validator';
export class MediaUploadUrlDto {
@IsString()
link: string
link: string;
}

View file

@ -59,7 +59,11 @@ export class MediaService {
return allowedTypes.includes(mimeType);
}
public async saveFile(fileBuffer: Buffer, username: string, noteId: string): Promise<string> {
public async saveFile(
fileBuffer: Buffer,
username: string,
noteId: string,
): Promise<string> {
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,
}
};
}
}

View file

@ -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<Note> {
async updateNoteByIdOrAlias(
noteIdOrAlias: string,
noteContent: string,
): Promise<Note> {
const note = await this.getNoteByIdOrAlias(noteIdOrAlias);
const revisions = await note.revisions;
//TODO: Calculate patch
@ -142,7 +145,7 @@ export class NotesService {
return {
id: 'foobar-barfoo',
alias: null,
shortid: "abc",
shortid: 'abc',
owner: {
authTokens: [],
createdAt: new Date(),
@ -180,7 +183,7 @@ export class NotesService {
group: noteGroupPermission.group,
canEdit: noteGroupPermission.canEdit,
})),
}
};
}
async toNoteMetadataDto(note: Note): Promise<NoteMetadataDto> {

View file

@ -24,9 +24,7 @@ export class RevisionsService {
this.logger.setContext(RevisionsService.name);
}
async getAllRevisions(
noteIdOrAlias: string,
): Promise<Revision[]> {
async getAllRevisions(noteIdOrAlias: string): Promise<Revision[]> {
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
return await this.revisionRepository.find({
where: {