Merge pull request #1047 from hedgedoc/docs/apidocs

This commit is contained in:
David Mehren 2021-03-21 19:07:14 +01:00 committed by GitHub
commit 6d8780de4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 307 additions and 14 deletions

View file

@ -23,14 +23,25 @@ import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
import { NotesService } from '../../../notes/notes.service'; import { NotesService } from '../../../notes/notes.service';
import { UsersService } from '../../../users/users.service'; import { UsersService } from '../../../users/users.service';
import { TokenAuthGuard } from '../../../auth/token-auth.guard'; import { TokenAuthGuard } from '../../../auth/token-auth.guard';
import { ApiSecurity, ApiTags } from '@nestjs/swagger'; import {
ApiNoContentResponse,
ApiNotFoundResponse,
ApiOkResponse,
ApiSecurity,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { HistoryEntryDto } from '../../../history/history-entry.dto'; import { HistoryEntryDto } from '../../../history/history-entry.dto';
import { UserInfoDto } from '../../../users/user-info.dto'; import { UserInfoDto } from '../../../users/user-info.dto';
import { NotInDBError } from '../../../errors/errors'; import { NotInDBError } from '../../../errors/errors';
import { Request } from 'express'; import { Request } from 'express';
import { MediaService } from '../../../media/media.service'; import { MediaService } from '../../../media/media.service';
import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto';
import { MediaUploadDto } from '../../../media/media-upload.dto'; import { MediaUploadDto } from '../../../media/media-upload.dto';
import {
notFoundDescription,
successfullyDeletedDescription,
unauthorizedDescription,
} from '../../utils/descriptions';
@ApiTags('me') @ApiTags('me')
@ApiSecurity('token') @ApiSecurity('token')
@ -48,6 +59,11 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get() @Get()
@ApiOkResponse({
description: 'The user information',
type: UserInfoDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
async getMe(@Req() req: Request): Promise<UserInfoDto> { async getMe(@Req() req: Request): Promise<UserInfoDto> {
return this.usersService.toUserDto( return this.usersService.toUserDto(
await this.usersService.getUserByUsername(req.user.userName), await this.usersService.getUserByUsername(req.user.userName),
@ -56,6 +72,12 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('history') @Get('history')
@ApiOkResponse({
description: 'The history entries of the user',
isArray: true,
type: HistoryEntryDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
async getUserHistory(@Req() req: Request): Promise<HistoryEntryDto[]> { async getUserHistory(@Req() req: Request): Promise<HistoryEntryDto[]> {
const foundEntries = await this.historyService.getEntriesByUser(req.user); const foundEntries = await this.historyService.getEntriesByUser(req.user);
return await Promise.all( return await Promise.all(
@ -65,6 +87,12 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('history/:note') @Get('history/:note')
@ApiOkResponse({
description: 'The history entry of the user which points to the note',
type: HistoryEntryDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async getHistoryEntry( async getHistoryEntry(
@Req() req: Request, @Req() req: Request,
@Param('note') note: string, @Param('note') note: string,
@ -85,6 +113,12 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Put('history/:note') @Put('history/:note')
@ApiOkResponse({
description: 'The updated history entry',
type: HistoryEntryDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async updateHistoryEntry( async updateHistoryEntry(
@Req() req: Request, @Req() req: Request,
@Param('note') note: string, @Param('note') note: string,
@ -110,6 +144,9 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Delete('history/:note') @Delete('history/:note')
@HttpCode(204) @HttpCode(204)
@ApiNoContentResponse({ description: successfullyDeletedDescription })
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async deleteHistoryEntry( async deleteHistoryEntry(
@Req() req: Request, @Req() req: Request,
@Param('note') note: string, @Param('note') note: string,
@ -127,6 +164,12 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('notes') @Get('notes')
@ApiOkResponse({
description: 'Metadata of all notes of the user',
isArray: true,
type: NoteMetadataDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
async getMyNotes(@Req() req: Request): Promise<NoteMetadataDto[]> { async getMyNotes(@Req() req: Request): Promise<NoteMetadataDto[]> {
const notes = this.notesService.getUserNotes(req.user); const notes = this.notesService.getUserNotes(req.user);
return await Promise.all( return await Promise.all(
@ -136,6 +179,12 @@ export class MeController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('media') @Get('media')
@ApiOkResponse({
description: 'All media uploads of the user',
isArray: true,
type: MediaUploadDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
async getMyMedia(@Req() req: Request): Promise<MediaUploadDto[]> { async getMyMedia(@Req() req: Request): Promise<MediaUploadDto[]> {
const media = await this.mediaService.listUploadsByUser(req.user); const media = await this.mediaService.listUploadsByUser(req.user);
return media.map((media) => this.mediaService.toMediaUploadDto(media)); return media.map((media) => this.mediaService.toMediaUploadDto(media));

View file

@ -9,6 +9,7 @@ import {
Controller, Controller,
Delete, Delete,
Headers, Headers,
HttpCode,
InternalServerErrorException, InternalServerErrorException,
NotFoundException, NotFoundException,
Param, Param,
@ -31,8 +32,25 @@ import { ConsoleLoggerService } from '../../../logger/console-logger.service';
import { MediaService } from '../../../media/media.service'; import { MediaService } from '../../../media/media.service';
import { MulterFile } from '../../../media/multer-file.interface'; import { MulterFile } from '../../../media/multer-file.interface';
import { TokenAuthGuard } from '../../../auth/token-auth.guard'; import { TokenAuthGuard } from '../../../auth/token-auth.guard';
import { ApiSecurity, ApiTags } from '@nestjs/swagger'; import {
ApiBody,
ApiConsumes,
ApiCreatedResponse,
ApiForbiddenResponse,
ApiHeader,
ApiNoContentResponse,
ApiNotFoundResponse,
ApiSecurity,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto'; import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto';
import {
forbiddenDescription,
notFoundDescription,
successfullyDeletedDescription,
unauthorizedDescription,
} from '../../utils/descriptions';
@ApiTags('media') @ApiTags('media')
@ApiSecurity('token') @ApiSecurity('token')
@ -47,7 +65,22 @@ export class MediaController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Post() @Post()
@ApiConsumes('multipart/form-data')
@ApiBody({
description: 'The binary file to upload',
})
@ApiHeader({
name: 'HedgeDoc-Note',
description: 'ID or alias of the parent note',
})
@ApiCreatedResponse({
description: 'The file was uploaded successfully',
type: MediaUploadUrlDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@UseInterceptors(FileInterceptor('file')) @UseInterceptors(FileInterceptor('file'))
@HttpCode(201)
async uploadMedia( async uploadMedia(
@Req() req: Request, @Req() req: Request,
@UploadedFile() file: MulterFile, @UploadedFile() file: MulterFile,
@ -80,6 +113,11 @@ export class MediaController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Delete(':filename') @Delete(':filename')
@HttpCode(204)
@ApiNoContentResponse({ description: successfullyDeletedDescription })
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async deleteMedia( async deleteMedia(
@Req() req: Request, @Req() req: Request,
@Param('filename') filename: string, @Param('filename') filename: string,

View file

@ -7,8 +7,19 @@
import { Controller, Get, UseGuards } from '@nestjs/common'; import { Controller, Get, UseGuards } from '@nestjs/common';
import { MonitoringService } from '../../../monitoring/monitoring.service'; import { MonitoringService } from '../../../monitoring/monitoring.service';
import { TokenAuthGuard } from '../../../auth/token-auth.guard'; import { TokenAuthGuard } from '../../../auth/token-auth.guard';
import { ApiSecurity, ApiTags } from '@nestjs/swagger'; import {
ApiForbiddenResponse,
ApiOkResponse,
ApiProduces,
ApiSecurity,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { ServerStatusDto } from '../../../monitoring/server-status.dto'; import { ServerStatusDto } from '../../../monitoring/server-status.dto';
import {
forbiddenDescription,
unauthorizedDescription,
} from '../../utils/descriptions';
@ApiTags('monitoring') @ApiTags('monitoring')
@ApiSecurity('token') @ApiSecurity('token')
@ -18,6 +29,12 @@ export class MonitoringController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get() @Get()
@ApiOkResponse({
description: 'The server info',
type: ServerStatusDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
getStatus(): Promise<ServerStatusDto> { getStatus(): Promise<ServerStatusDto> {
// TODO: toServerStatusDto. // TODO: toServerStatusDto.
return this.monitoringService.getServerStatus(); return this.monitoringService.getServerStatus();
@ -25,6 +42,12 @@ export class MonitoringController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get('prometheus') @Get('prometheus')
@ApiOkResponse({
description: 'Prometheus compatible monitoring data',
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiProduces('text/plain')
getPrometheusStatus(): string { getPrometheusStatus(): string {
return ''; return '';
} }

View file

@ -11,6 +11,7 @@ import {
Delete, Delete,
Get, Get,
Header, Header,
HttpCode,
NotFoundException, NotFoundException,
Param, Param,
Post, Post,
@ -34,7 +35,17 @@ import { NotesService } from '../../../notes/notes.service';
import { RevisionsService } from '../../../revisions/revisions.service'; import { RevisionsService } from '../../../revisions/revisions.service';
import { MarkdownBody } from '../../utils/markdownbody-decorator'; import { MarkdownBody } from '../../utils/markdownbody-decorator';
import { TokenAuthGuard } from '../../../auth/token-auth.guard'; import { TokenAuthGuard } from '../../../auth/token-auth.guard';
import { ApiSecurity, ApiTags } from '@nestjs/swagger'; import {
ApiCreatedResponse,
ApiForbiddenResponse,
ApiNoContentResponse,
ApiNotFoundResponse,
ApiOkResponse,
ApiProduces,
ApiSecurity,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { HistoryService } from '../../../history/history.service'; import { HistoryService } from '../../../history/history.service';
import { NoteDto } from '../../../notes/note.dto'; import { NoteDto } from '../../../notes/note.dto';
import { NoteMetadataDto } from '../../../notes/note-metadata.dto'; import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
@ -43,6 +54,12 @@ import { RevisionDto } from '../../../revisions/revision.dto';
import { PermissionsService } from '../../../permissions/permissions.service'; import { PermissionsService } from '../../../permissions/permissions.service';
import { Note } from '../../../notes/note.entity'; import { Note } from '../../../notes/note.entity';
import { Request } from 'express'; import { Request } from 'express';
import {
forbiddenDescription,
notFoundDescription,
successfullyDeletedDescription,
unauthorizedDescription,
} from '../../utils/descriptions';
@ApiTags('notes') @ApiTags('notes')
@ApiSecurity('token') @ApiSecurity('token')
@ -60,6 +77,9 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Post() @Post()
@HttpCode(201)
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
async createNote( async createNote(
@Req() req: Request, @Req() req: Request,
@MarkdownBody() text: string, @MarkdownBody() text: string,
@ -76,6 +96,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias') @Get(':noteIdOrAlias')
@ApiOkResponse({
description: 'Get information about the newly created note',
type: NoteDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async getNote( async getNote(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@ -101,6 +128,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Post(':noteAlias') @Post(':noteAlias')
@HttpCode(201)
@ApiCreatedResponse({
description: 'Get information about the newly created note',
type: NoteDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
async createNamedNote( async createNamedNote(
@Req() req: Request, @Req() req: Request,
@Param('noteAlias') noteAlias: string, @Param('noteAlias') noteAlias: string,
@ -127,6 +161,11 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Delete(':noteIdOrAlias') @Delete(':noteIdOrAlias')
@HttpCode(204)
@ApiNoContentResponse({ description: successfullyDeletedDescription })
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async deleteNote( async deleteNote(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@ -153,6 +192,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Put(':noteIdOrAlias') @Put(':noteIdOrAlias')
@ApiOkResponse({
description: 'The new, changed note',
type: NoteDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async updateNote( async updateNote(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@ -180,6 +226,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/content') @Get(':noteIdOrAlias/content')
@ApiProduces('text/markdown')
@ApiOkResponse({
description: 'The raw markdown content of the note',
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
@Header('content-type', 'text/markdown') @Header('content-type', 'text/markdown')
async getNoteContent( async getNoteContent(
@Req() req: Request, @Req() req: Request,
@ -204,6 +257,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/metadata') @Get(':noteIdOrAlias/metadata')
@ApiOkResponse({
description: 'The metadata of the note',
type: NoteMetadataDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async getNoteMetadata( async getNoteMetadata(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@ -230,6 +290,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Put(':noteIdOrAlias/metadata/permissions') @Put(':noteIdOrAlias/metadata/permissions')
@ApiOkResponse({
description: 'The updated permissions of the note',
type: NotePermissionsDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async updateNotePermissions( async updateNotePermissions(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@ -256,6 +323,14 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/revisions') @Get(':noteIdOrAlias/revisions')
@ApiOkResponse({
description: 'Revisions of the note',
isArray: true,
type: RevisionMetadataDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async getNoteRevisions( async getNoteRevisions(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,
@ -284,6 +359,13 @@ export class NotesController {
@UseGuards(TokenAuthGuard) @UseGuards(TokenAuthGuard)
@Get(':noteIdOrAlias/revisions/:revisionId') @Get(':noteIdOrAlias/revisions/:revisionId')
@ApiOkResponse({
description: 'Revision of the note for the given id or alias',
type: RevisionDto,
})
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiForbiddenResponse({ description: forbiddenDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async getNoteRevision( async getNoteRevision(
@Req() req: Request, @Req() req: Request,
@Param('noteIdOrAlias') noteIdOrAlias: string, @Param('noteIdOrAlias') noteIdOrAlias: string,

View file

@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
export const unauthorizedDescription =
'Authorization information is missing or invalid';
export const forbiddenDescription =
'Access to the requested resource is not permitted';
export const notFoundDescription = 'The requested resource was not found';
export const successfullyDeletedDescription =
'The requested resource was sucessfully deleted';

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { IsBoolean, IsString } from 'class-validator'; import { IsBoolean, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class GroupInfoDto { export class GroupInfoDto {
/** /**
@ -11,6 +12,7 @@ export class GroupInfoDto {
* @example "superheroes" * @example "superheroes"
*/ */
@IsString() @IsString()
@ApiProperty()
name: string; name: string;
/** /**
@ -18,6 +20,7 @@ export class GroupInfoDto {
* @example "Superheroes" * @example "Superheroes"
*/ */
@IsString() @IsString()
@ApiProperty()
displayName: string; displayName: string;
/** /**
@ -26,5 +29,6 @@ export class GroupInfoDto {
* @example false * @example false
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
special: boolean; special: boolean;
} }

View file

@ -5,11 +5,13 @@
*/ */
import { IsBoolean } from 'class-validator'; import { IsBoolean } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class HistoryEntryUpdateDto { export class HistoryEntryUpdateDto {
/** /**
* True if the note should be pinned * True if the note should be pinned
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
pinStatus: boolean; pinStatus: boolean;
} }

View file

@ -5,12 +5,14 @@
*/ */
import { IsArray, IsBoolean, IsDate, IsString } from 'class-validator'; import { IsArray, IsBoolean, IsDate, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class HistoryEntryDto { export class HistoryEntryDto {
/** /**
* ID or Alias of the note * ID or Alias of the note
*/ */
@IsString() @IsString()
@ApiProperty()
identifier: string; identifier: string;
/** /**
@ -19,6 +21,7 @@ export class HistoryEntryDto {
* @example "Shopping List" * @example "Shopping List"
*/ */
@IsString() @IsString()
@ApiProperty()
title: string; title: string;
/** /**
@ -26,10 +29,12 @@ export class HistoryEntryDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
lastVisited: Date; lastVisited: Date;
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty()
tags: string[]; tags: string[];
/** /**
@ -37,5 +42,6 @@ export class HistoryEntryDto {
* @example false * @example false
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
pinStatus: boolean; pinStatus: boolean;
} }

View file

@ -5,8 +5,10 @@
*/ */
import { IsString } from 'class-validator'; import { IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class MediaUploadUrlDto { export class MediaUploadUrlDto {
@IsString() @IsString()
@ApiProperty()
link: string; link: string;
} }

View file

@ -5,6 +5,7 @@
*/ */
import { IsDate, IsString } from 'class-validator'; import { IsDate, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class MediaUploadDto { export class MediaUploadDto {
/** /**
@ -12,6 +13,7 @@ export class MediaUploadDto {
* @example "https://example.com/uploads/testfile123.jpg" * @example "https://example.com/uploads/testfile123.jpg"
*/ */
@IsString() @IsString()
@ApiProperty()
url: string; url: string;
/** /**
@ -19,6 +21,7 @@ export class MediaUploadDto {
* @example "noteId" TODO how looks a note id? * @example "noteId" TODO how looks a note id?
*/ */
@IsString() @IsString()
@ApiProperty()
noteId: string; noteId: string;
/** /**
@ -26,6 +29,7 @@ export class MediaUploadDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
createdAt: Date; createdAt: Date;
/** /**
@ -33,5 +37,6 @@ export class MediaUploadDto {
* @example "testuser5" * @example "testuser5"
*/ */
@IsString() @IsString()
@ApiProperty()
userName: string; userName: string;
} }

View file

@ -38,10 +38,10 @@ async function getServerVersionFromPackageJson(): Promise<ServerVersion> {
export class MonitoringService { export class MonitoringService {
async getServerStatus(): Promise<ServerStatusDto> { async getServerStatus(): Promise<ServerStatusDto> {
return { return {
connectionSocketQueueLenght: 0, connectionSocketQueueLength: 0,
destictOnlineUsers: 0, distinctOnlineUsers: 0,
disconnectSocketQueueLength: 0, disconnectSocketQueueLength: 0,
distictOnlineRegisteredUsers: 0, distinctOnlineRegisteredUsers: 0,
isConnectionBusy: false, isConnectionBusy: false,
isDisconnectBusy: false, isDisconnectBusy: false,
notesCount: 0, notesCount: 0,

View file

@ -4,25 +4,44 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
export interface ServerVersion { import { ApiProperty } from '@nestjs/swagger';
export class ServerVersion {
@ApiProperty()
major: number; major: number;
@ApiProperty()
minor: number; minor: number;
@ApiProperty()
patch: number; patch: number;
@ApiProperty()
preRelease?: string; preRelease?: string;
@ApiProperty()
commit?: string; commit?: string;
} }
export class ServerStatusDto { export class ServerStatusDto {
@ApiProperty()
serverVersion: ServerVersion; serverVersion: ServerVersion;
@ApiProperty()
onlineNotes: number; onlineNotes: number;
@ApiProperty()
onlineUsers: number; onlineUsers: number;
destictOnlineUsers: number; @ApiProperty()
distinctOnlineUsers: number;
@ApiProperty()
notesCount: number; notesCount: number;
@ApiProperty()
registeredUsers: number; registeredUsers: number;
@ApiProperty()
onlineRegisteredUsers: number; onlineRegisteredUsers: number;
distictOnlineRegisteredUsers: number; @ApiProperty()
distinctOnlineRegisteredUsers: number;
@ApiProperty()
isConnectionBusy: boolean; isConnectionBusy: boolean;
connectionSocketQueueLenght: number; @ApiProperty()
connectionSocketQueueLength: number;
@ApiProperty()
isDisconnectBusy: boolean; isDisconnectBusy: boolean;
@ApiProperty()
disconnectSocketQueueLength: number; disconnectSocketQueueLength: number;
} }

View file

@ -6,6 +6,7 @@
import { IsDate, IsNumber, IsString, Min } from 'class-validator'; import { IsDate, IsNumber, IsString, Min } from 'class-validator';
import { UserInfoDto } from '../users/user-info.dto'; import { UserInfoDto } from '../users/user-info.dto';
import { ApiProperty } from '@nestjs/swagger';
export class NoteAuthorshipDto { export class NoteAuthorshipDto {
/** /**
@ -13,6 +14,7 @@ export class NoteAuthorshipDto {
* @example "john.smith" * @example "john.smith"
*/ */
@IsString() @IsString()
@ApiProperty()
userName: UserInfoDto['userName']; userName: UserInfoDto['userName'];
/** /**
@ -21,6 +23,7 @@ export class NoteAuthorshipDto {
*/ */
@IsNumber() @IsNumber()
@Min(0) @Min(0)
@ApiProperty()
startPos: number; startPos: number;
/** /**
@ -30,6 +33,7 @@ export class NoteAuthorshipDto {
*/ */
@IsNumber() @IsNumber()
@Min(0) @Min(0)
@ApiProperty()
endPos: number; endPos: number;
/** /**
@ -37,6 +41,7 @@ export class NoteAuthorshipDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
createdAt: Date; createdAt: Date;
/** /**
@ -44,5 +49,6 @@ export class NoteAuthorshipDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
updatedAt: Date; updatedAt: Date;
} }

View file

@ -14,12 +14,14 @@ import {
} from 'class-validator'; } from 'class-validator';
import { UserInfoDto } from '../users/user-info.dto'; import { UserInfoDto } from '../users/user-info.dto';
import { NotePermissionsDto } from './note-permissions.dto'; import { NotePermissionsDto } from './note-permissions.dto';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class NoteMetadataDto { export class NoteMetadataDto {
/** /**
* ID of the note * ID of the note
*/ */
@IsString() @IsString()
@ApiProperty()
id: string; id: string;
/** /**
@ -28,6 +30,7 @@ export class NoteMetadataDto {
*/ */
@IsString() @IsString()
@IsOptional() @IsOptional()
@ApiPropertyOptional()
alias: string; alias: string;
/** /**
@ -36,6 +39,7 @@ export class NoteMetadataDto {
* @example "Shopping List" * @example "Shopping List"
*/ */
@IsString() @IsString()
@ApiProperty()
title: string; title: string;
/** /**
@ -44,6 +48,7 @@ export class NoteMetadataDto {
* @example Everything I want to buy * @example Everything I want to buy
*/ */
@IsString() @IsString()
@ApiProperty()
description: string; description: string;
/** /**
@ -52,6 +57,7 @@ export class NoteMetadataDto {
*/ */
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty()
tags: string[]; tags: string[];
/** /**
@ -59,12 +65,14 @@ export class NoteMetadataDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
updateTime: Date; updateTime: Date;
/** /**
* User that last edited the note * User that last edited the note
*/ */
@ValidateNested() @ValidateNested()
@ApiProperty({ type: UserInfoDto })
updateUser: UserInfoDto; updateUser: UserInfoDto;
/** /**
@ -72,6 +80,7 @@ export class NoteMetadataDto {
* @example 42 * @example 42
*/ */
@IsNumber() @IsNumber()
@ApiProperty()
viewCount: number; viewCount: number;
/** /**
@ -79,6 +88,7 @@ export class NoteMetadataDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
createTime: Date; createTime: Date;
/** /**
@ -87,12 +97,14 @@ export class NoteMetadataDto {
*/ */
@IsArray() @IsArray()
@ValidateNested() @ValidateNested()
@ApiProperty()
editedBy: UserInfoDto['userName'][]; editedBy: UserInfoDto['userName'][];
/** /**
* Permissions currently in effect for the note * Permissions currently in effect for the note
*/ */
@ValidateNested() @ValidateNested()
@ApiProperty({ type: NotePermissionsDto })
permissions: NotePermissionsDto; permissions: NotePermissionsDto;
} }
@ -103,6 +115,7 @@ export class NoteMetadataUpdateDto {
* @example "Shopping List" * @example "Shopping List"
*/ */
@IsString() @IsString()
@ApiProperty()
title: string; title: string;
/** /**
@ -111,6 +124,7 @@ export class NoteMetadataUpdateDto {
* @example Everything I want to buy * @example Everything I want to buy
*/ */
@IsString() @IsString()
@ApiProperty()
description: string; description: string;
/** /**
@ -119,5 +133,6 @@ export class NoteMetadataUpdateDto {
*/ */
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty()
tags: string[]; tags: string[];
} }

View file

@ -7,12 +7,14 @@
import { IsArray, IsBoolean, IsString, ValidateNested } from 'class-validator'; import { IsArray, IsBoolean, IsString, ValidateNested } from 'class-validator';
import { UserInfoDto } from '../users/user-info.dto'; import { UserInfoDto } from '../users/user-info.dto';
import { GroupInfoDto } from '../groups/group-info.dto'; import { GroupInfoDto } from '../groups/group-info.dto';
import { ApiProperty } from '@nestjs/swagger';
export class NoteUserPermissionEntryDto { export class NoteUserPermissionEntryDto {
/** /**
* User this permission applies to * User this permission applies to
*/ */
@ValidateNested() @ValidateNested()
@ApiProperty({ type: UserInfoDto })
user: UserInfoDto; user: UserInfoDto;
/** /**
@ -20,6 +22,7 @@ export class NoteUserPermissionEntryDto {
* @example false * @example false
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
canEdit: boolean; canEdit: boolean;
} }
@ -29,6 +32,7 @@ export class NoteUserPermissionUpdateDto {
* @example "john.smith" * @example "john.smith"
*/ */
@IsString() @IsString()
@ApiProperty()
username: string; username: string;
/** /**
@ -36,6 +40,7 @@ export class NoteUserPermissionUpdateDto {
* @example false * @example false
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
canEdit: boolean; canEdit: boolean;
} }
@ -44,6 +49,7 @@ export class NoteGroupPermissionEntryDto {
* Group this permission applies to * Group this permission applies to
*/ */
@ValidateNested() @ValidateNested()
@ApiProperty({ type: GroupInfoDto })
group: GroupInfoDto; group: GroupInfoDto;
/** /**
@ -51,6 +57,7 @@ export class NoteGroupPermissionEntryDto {
* @example false * @example false
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
canEdit: boolean; canEdit: boolean;
} }
@ -60,6 +67,7 @@ export class NoteGroupPermissionUpdateDto {
* @example "superheroes" * @example "superheroes"
*/ */
@IsString() @IsString()
@ApiProperty()
groupname: string; groupname: string;
/** /**
@ -67,6 +75,7 @@ export class NoteGroupPermissionUpdateDto {
* @example false * @example false
*/ */
@IsBoolean() @IsBoolean()
@ApiProperty()
canEdit: boolean; canEdit: boolean;
} }
@ -75,6 +84,7 @@ export class NotePermissionsDto {
* User this permission applies to * User this permission applies to
*/ */
@ValidateNested() @ValidateNested()
@ApiProperty({ type: UserInfoDto })
owner: UserInfoDto; owner: UserInfoDto;
/** /**
@ -82,6 +92,7 @@ export class NotePermissionsDto {
*/ */
@ValidateNested() @ValidateNested()
@IsArray() @IsArray()
@ApiProperty({ isArray: true, type: NoteUserPermissionEntryDto })
sharedToUsers: NoteUserPermissionEntryDto[]; sharedToUsers: NoteUserPermissionEntryDto[];
/** /**
@ -89,6 +100,7 @@ export class NotePermissionsDto {
*/ */
@ValidateNested() @ValidateNested()
@IsArray() @IsArray()
@ApiProperty({ isArray: true, type: NoteGroupPermissionEntryDto })
sharedToGroups: NoteGroupPermissionEntryDto[]; sharedToGroups: NoteGroupPermissionEntryDto[];
} }
@ -98,6 +110,7 @@ export class NotePermissionsUpdateDto {
*/ */
@IsArray() @IsArray()
@ValidateNested() @ValidateNested()
@ApiProperty({ isArray: true, type: NoteUserPermissionUpdateDto })
sharedToUsers: NoteUserPermissionUpdateDto[]; sharedToUsers: NoteUserPermissionUpdateDto[];
/** /**
@ -105,5 +118,6 @@ export class NotePermissionsUpdateDto {
*/ */
@IsArray() @IsArray()
@ValidateNested() @ValidateNested()
@ApiProperty({ isArray: true, type: NoteGroupPermissionUpdateDto })
sharedToGroups: NoteGroupPermissionUpdateDto[]; sharedToGroups: NoteGroupPermissionUpdateDto[];
} }

View file

@ -7,6 +7,7 @@
import { IsArray, IsString, ValidateNested } from 'class-validator'; import { IsArray, IsString, ValidateNested } from 'class-validator';
import { NoteAuthorshipDto } from './note-authorship.dto'; import { NoteAuthorshipDto } from './note-authorship.dto';
import { NoteMetadataDto } from './note-metadata.dto'; import { NoteMetadataDto } from './note-metadata.dto';
import { ApiProperty } from '@nestjs/swagger';
export class NoteDto { export class NoteDto {
/** /**
@ -14,12 +15,14 @@ export class NoteDto {
* @example "# I am a heading" * @example "# I am a heading"
*/ */
@IsString() @IsString()
@ApiProperty()
content: string; content: string;
/** /**
* Metadata of the note * Metadata of the note
*/ */
@ValidateNested() @ValidateNested()
@ApiProperty({ type: NoteMetadataDto })
metadata: NoteMetadataDto; metadata: NoteMetadataDto;
/** /**
@ -27,5 +30,6 @@ export class NoteDto {
*/ */
@IsArray() @IsArray()
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@ApiProperty({ isArray: true, type: NoteAuthorshipDto })
editedByAtPosition: NoteAuthorshipDto[]; editedByAtPosition: NoteAuthorshipDto[];
} }

View file

@ -6,6 +6,7 @@
import { IsDate, IsNumber } from 'class-validator'; import { IsDate, IsNumber } from 'class-validator';
import { Revision } from './revision.entity'; import { Revision } from './revision.entity';
import { ApiProperty } from '@nestjs/swagger';
export class RevisionMetadataDto { export class RevisionMetadataDto {
/** /**
@ -13,6 +14,7 @@ export class RevisionMetadataDto {
* @example 13 * @example 13
*/ */
@IsNumber() @IsNumber()
@ApiProperty()
id: Revision['id']; id: Revision['id'];
/** /**
@ -20,6 +22,7 @@ export class RevisionMetadataDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
createdAt: Date; createdAt: Date;
/** /**
@ -27,5 +30,6 @@ export class RevisionMetadataDto {
* @example 142 * @example 142
*/ */
@IsNumber() @IsNumber()
@ApiProperty()
length: number; length: number;
} }

View file

@ -6,6 +6,7 @@
import { IsDate, IsNumber, IsString } from 'class-validator'; import { IsDate, IsNumber, IsString } from 'class-validator';
import { Revision } from './revision.entity'; import { Revision } from './revision.entity';
import { ApiProperty } from '@nestjs/swagger';
export class RevisionDto { export class RevisionDto {
/** /**
@ -13,6 +14,7 @@ export class RevisionDto {
* @example 13 * @example 13
*/ */
@IsNumber() @IsNumber()
@ApiProperty()
id: Revision['id']; id: Revision['id'];
/** /**
@ -20,12 +22,14 @@ export class RevisionDto {
* @example "# I am a heading" * @example "# I am a heading"
*/ */
@IsString() @IsString()
@ApiProperty()
content: string; content: string;
/** /**
* Patch from the preceding revision to this one * Patch from the preceding revision to this one
*/ */
@IsString() @IsString()
@ApiProperty()
patch: string; patch: string;
/** /**
@ -33,5 +37,6 @@ export class RevisionDto {
* @example "2020-12-01 12:23:34" * @example "2020-12-01 12:23:34"
*/ */
@IsDate() @IsDate()
@ApiProperty()
createdAt: Date; createdAt: Date;
} }

View file

@ -13,6 +13,7 @@ export class UserInfoDto {
* @example "john.smith" * @example "john.smith"
*/ */
@IsString() @IsString()
@ApiProperty()
userName: string; userName: string;
/** /**
@ -20,6 +21,7 @@ export class UserInfoDto {
* @example "John Smith" * @example "John Smith"
*/ */
@IsString() @IsString()
@ApiProperty()
displayName: string; displayName: string;
/** /**

View file

@ -104,7 +104,7 @@ describe('Notes', () => {
const filename = url.split('/').pop(); const filename = url.split('/').pop();
await request(app.getHttpServer()) await request(app.getHttpServer())
.delete('/media/' + filename) .delete('/media/' + filename)
.expect(200); .expect(204);
}); });
afterAll(async () => { afterAll(async () => {

View file

@ -146,7 +146,7 @@ describe('Notes', () => {
describe('DELETE /notes/{note}', () => { describe('DELETE /notes/{note}', () => {
it('works with an existing alias', async () => { it('works with an existing alias', async () => {
await notesService.createNote(content, 'test3', user); await notesService.createNote(content, 'test3', user);
await request(app.getHttpServer()).delete('/notes/test3').expect(200); await request(app.getHttpServer()).delete('/notes/test3').expect(204);
await expect(notesService.getNoteByIdOrAlias('test3')).rejects.toEqual( await expect(notesService.getNoteByIdOrAlias('test3')).rejects.toEqual(
new NotInDBError("Note with id/alias 'test3' not found."), new NotInDBError("Note with id/alias 'test3' not found."),
); );