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 Philip Molares
parent a7f35aaeec
commit c2b6c6fe49
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

@ -48,7 +48,7 @@ export class MediaController {
@Request() req,
@UploadedFile() file: MulterFile,
@Headers('HedgeDoc-Note') noteId: string,
) : Promise<MediaUploadUrlDto> {
): Promise<MediaUploadUrlDto> {
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<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

@ -17,7 +17,7 @@ export class MonitoringController {
@UseGuards(TokenAuthGuard)
@Get()
getStatus() : Promise<ServerStatusDto> {
getStatus(): Promise<ServerStatusDto> {
// TODO: toServerStatusDto.
return this.monitoringService.getServerStatus();
}

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) {
@ -107,12 +116,12 @@ export class NotesController {
@Request() req,
@Param('noteIdOrAlias') noteIdOrAlias: string,
@MarkdownBody() text: string,
) : Promise<NoteDto> {
): Promise<NoteDto> {
// 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<string> {
): Promise<string> {
// 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<NoteMetadataDto> {
): Promise<NoteMetadataDto> {
// 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<NotePermissionsDto> {
): Promise<NotePermissionsDto> {
// 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<RevisionMetadataDto[]> {
): Promise<RevisionMetadataDto[]> {
// 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<RevisionDto> {
): Promise<RevisionDto> {
// 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
@ -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<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: {
@ -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