refactor(backend): fix nestjs-typed linting errors

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2023-06-25 19:35:38 +02:00 committed by Tilman Vatteroth
parent 8daffbb11b
commit a5d8c9cc33
16 changed files with 60 additions and 20 deletions

View file

@ -40,5 +40,6 @@ export class AuthTokenCreateDto extends BaseDto {
label: string; label: string;
@IsNumber() @IsNumber()
@Type(() => Number)
validUntil: TimestampMillis; validUntil: TimestampMillis;
} }

View file

@ -11,7 +11,8 @@ import { LoggerModule } from '../logger/logger.module';
import { UsersModule } from '../users/users.module'; import { UsersModule } from '../users/users.module';
import { AuthToken } from './auth-token.entity'; import { AuthToken } from './auth-token.entity';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { TokenStrategy } from './token.strategy'; import { MockAuthGuard } from './mock-auth.guard';
import { TokenAuthGuard, TokenStrategy } from './token.strategy';
@Module({ @Module({
imports: [ imports: [
@ -20,7 +21,7 @@ import { TokenStrategy } from './token.strategy';
LoggerModule, LoggerModule,
TypeOrmModule.forFeature([AuthToken]), TypeOrmModule.forFeature([AuthToken]),
], ],
providers: [AuthService, TokenStrategy], providers: [AuthService, TokenStrategy, MockAuthGuard, TokenAuthGuard],
exports: [AuthService], exports: [AuthService],
}) })
export class AuthModule {} export class AuthModule {}

View file

@ -3,6 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { Type } from 'class-transformer';
import { import {
IsArray, IsArray,
IsBoolean, IsBoolean,
@ -50,6 +51,7 @@ export class AuthProviderWithoutCustomNameDto extends BaseDto {
* The type of the auth provider. * The type of the auth provider.
*/ */
@IsString() @IsString()
@Type(() => String)
type: AuthProviderTypeWithoutCustomName; type: AuthProviderTypeWithoutCustomName;
} }
@ -58,6 +60,7 @@ export class AuthProviderWithCustomNameDto extends BaseDto {
* The type of the auth provider. * The type of the auth provider.
*/ */
@IsString() @IsString()
@Type(() => String)
type: AuthProviderTypeWithCustomName; type: AuthProviderTypeWithCustomName;
/** /**
@ -94,6 +97,7 @@ export class BrandingDto extends BaseDto {
*/ */
@IsUrl() @IsUrl()
@IsOptional() @IsOptional()
@Type(() => URL)
logo?: URL; logo?: URL;
} }
@ -104,6 +108,7 @@ export class SpecialUrlsDto extends BaseDto {
*/ */
@IsUrl() @IsUrl()
@IsOptional() @IsOptional()
@Type(() => URL)
privacy?: URL; privacy?: URL;
/** /**
@ -112,6 +117,7 @@ export class SpecialUrlsDto extends BaseDto {
*/ */
@IsUrl() @IsUrl()
@IsOptional() @IsOptional()
@Type(() => URL)
termsOfUse?: URL; termsOfUse?: URL;
/** /**
@ -120,6 +126,7 @@ export class SpecialUrlsDto extends BaseDto {
*/ */
@IsUrl() @IsUrl()
@IsOptional() @IsOptional()
@Type(() => URL)
imprint?: URL; imprint?: URL;
} }
@ -139,6 +146,7 @@ export class FrontendConfigDto extends BaseDto {
/** /**
* Which auth providers are enabled and how are they configured? * Which auth providers are enabled and how are they configured?
*/ */
// eslint-disable-next-line @darraghor/nestjs-typed/validated-non-primitive-property-needs-type-decorator
@IsArray() @IsArray()
@ValidateNested({ each: true }) @ValidateNested({ each: true })
authProviders: AuthProviderDto[]; authProviders: AuthProviderDto[];
@ -147,6 +155,7 @@ export class FrontendConfigDto extends BaseDto {
* Individual branding information * Individual branding information
*/ */
@ValidateNested() @ValidateNested()
@Type(() => BrandingDto)
branding: BrandingDto; branding: BrandingDto;
/** /**
@ -159,12 +168,14 @@ export class FrontendConfigDto extends BaseDto {
* Links to some special pages * Links to some special pages
*/ */
@ValidateNested() @ValidateNested()
@Type(() => SpecialUrlsDto)
specialUrls: SpecialUrlsDto; specialUrls: SpecialUrlsDto;
/** /**
* The version of HedgeDoc * The version of HedgeDoc
*/ */
@ValidateNested() @ValidateNested()
@Type(() => ServerVersion)
version: ServerVersion; version: ServerVersion;
/** /**
@ -172,6 +183,7 @@ export class FrontendConfigDto extends BaseDto {
*/ */
@IsUrl() @IsUrl()
@IsOptional() @IsOptional()
@Type(() => URL)
plantUmlServer?: URL; plantUmlServer?: URL;
/** /**

View file

@ -37,7 +37,7 @@ export class HistoryEntryDto extends BaseDto {
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty() @ApiProperty({ isArray: true, type: String })
tags: string[]; tags: string[];
/** /**

View file

@ -12,8 +12,8 @@ import { User } from '../users/user.entity';
import { UsersModule } from '../users/users.module'; import { UsersModule } from '../users/users.module';
import { Identity } from './identity.entity'; import { Identity } from './identity.entity';
import { IdentityService } from './identity.service'; import { IdentityService } from './identity.service';
import { LdapStrategy } from './ldap/ldap.strategy'; import { LdapAuthGuard, LdapStrategy } from './ldap/ldap.strategy';
import { LocalStrategy } from './local/local.strategy'; import { LocalAuthGuard, LocalStrategy } from './local/local.strategy';
@Module({ @Module({
imports: [ imports: [
@ -23,7 +23,13 @@ import { LocalStrategy } from './local/local.strategy';
LoggerModule, LoggerModule,
], ],
controllers: [], controllers: [],
providers: [IdentityService, LocalStrategy, LdapStrategy], providers: [
IdentityService,
LocalStrategy,
LdapStrategy,
LdapAuthGuard,
LocalAuthGuard,
],
exports: [IdentityService, LocalStrategy, LdapStrategy], exports: [IdentityService, LocalStrategy, LdapStrategy],
}) })
export class IdentityModule {} export class IdentityModule {}

View file

@ -3,11 +3,13 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { Type } from 'class-transformer';
import { IsLowercase, IsString } from 'class-validator'; import { IsLowercase, IsString } from 'class-validator';
import { Username } from '../../utils/username'; import { Username } from '../../utils/username';
export class LoginDto { export class LoginDto {
@Type(() => String)
@IsString() @IsString()
@IsLowercase() @IsLowercase()
username: Username; username: Username;

View file

@ -3,11 +3,13 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { Type } from 'class-transformer';
import { IsLowercase, IsString } from 'class-validator'; import { IsLowercase, IsString } from 'class-validator';
import { Username } from '../../utils/username'; import { Username } from '../../utils/username';
export class RegisterDto { export class RegisterDto {
@Type(() => String)
@IsString() @IsString()
@IsLowercase() @IsLowercase()
username: Username; username: Username;

View file

@ -43,6 +43,7 @@ export class MediaUploadDto extends BaseDto {
*/ */
@IsString() @IsString()
@IsLowercase() @IsLowercase()
@IsOptional()
@ApiProperty() @ApiProperty()
username: Username | null; username: Username | null;
} }

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { BaseDto } from '../utils/base.dto.'; import { BaseDto } from '../utils/base.dto.';
@ -14,9 +14,9 @@ export class ServerVersion {
minor: number; minor: number;
@ApiProperty() @ApiProperty()
patch: number; patch: number;
@ApiProperty() @ApiPropertyOptional()
preRelease?: string; preRelease?: string;
@ApiProperty() @ApiPropertyOptional()
commit?: string; commit?: string;
@ApiProperty() @ApiProperty()
fullString: string; fullString: string;

View file

@ -29,9 +29,10 @@ export class NoteMetadataDto extends BaseDto {
/** /**
* All aliases of the note (including the primaryAlias) * All aliases of the note (including the primaryAlias)
*/ */
@Type(() => AliasDto)
@IsArray() @IsArray()
@ValidateNested() @ValidateNested({ each: true })
@ApiProperty() @ApiProperty({ isArray: true, type: AliasDto })
aliases: AliasDto[]; aliases: AliasDto[];
/** /**
@ -67,7 +68,7 @@ export class NoteMetadataDto extends BaseDto {
*/ */
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty() @ApiProperty({ isArray: true, type: String })
tags: string[]; tags: string[];
@IsNumber() @IsNumber()
@ -86,8 +87,9 @@ export class NoteMetadataDto extends BaseDto {
/** /**
* User that last edited the note * User that last edited the note
*/ */
@IsString() // eslint-disable-next-line @darraghor/nestjs-typed/api-property-matches-property-optionality
@ApiPropertyOptional() @ApiPropertyOptional()
@IsString()
@IsOptional() @IsOptional()
updateUsername: string | null; updateUsername: string | null;
@ -114,13 +116,13 @@ export class NoteMetadataDto extends BaseDto {
*/ */
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty() @ApiProperty({ isArray: true, type: String })
editedBy: string[]; editedBy: string[];
/** /**
* Permissions currently in effect for the note * Permissions currently in effect for the note
*/ */
@ValidateNested({ each: true }) @ValidateNested()
@Type(() => NotePermissionsDto) @Type(() => NotePermissionsDto)
@ApiProperty({ type: NotePermissionsDto }) @ApiProperty({ type: NotePermissionsDto })
permissions: NotePermissionsDto; permissions: NotePermissionsDto;
@ -151,6 +153,6 @@ export class NoteMetadataUpdateDto {
*/ */
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty() @ApiProperty({ isArray: true, type: String })
tags: string[]; tags: string[];
} }

View file

@ -21,6 +21,7 @@ export class NoteUserPermissionEntryDto extends BaseDto {
/** /**
* Username of the User this permission applies to * Username of the User this permission applies to
*/ */
@Type(() => String)
@IsString() @IsString()
@IsLowercase() @IsLowercase()
@ApiProperty() @ApiProperty()
@ -40,6 +41,7 @@ export class NoteUserPermissionUpdateDto {
* Username of the user this permission should apply to * Username of the user this permission should apply to
* @example "john.smith" * @example "john.smith"
*/ */
@Type(() => String)
@IsString() @IsString()
@IsLowercase() @IsLowercase()
@ApiProperty() @ApiProperty()
@ -93,6 +95,9 @@ export class NotePermissionsDto {
/** /**
* Username of the User this permission applies to * Username of the User this permission applies to
*/ */
// nestjs-typed does not detect '| null' types as optional
// eslint-disable-next-line @darraghor/nestjs-typed/api-property-matches-property-optionality
@Type(() => String)
@IsString() @IsString()
@ApiPropertyOptional() @ApiPropertyOptional()
@IsOptional() @IsOptional()

View file

@ -23,6 +23,7 @@ export class NoteDto extends BaseDto {
/** /**
* Metadata of the note * Metadata of the note
*/ */
@Type(() => NoteMetadataDto)
@ValidateNested() @ValidateNested()
@ApiProperty({ type: NoteMetadataDto }) @ApiProperty({ type: NoteMetadataDto })
metadata: NoteMetadataDto; metadata: NoteMetadataDto;

View file

@ -16,6 +16,8 @@ export class EditDto extends BaseDto {
* Is `null` if the user is anonymous * Is `null` if the user is anonymous
* @example "john.smith" * @example "john.smith"
*/ */
// nestjs-typed does not detect '| null' types as optional
// eslint-disable-next-line @darraghor/nestjs-typed/api-property-matches-property-optionality
@IsString() @IsString()
@IsOptional() @IsOptional()
@ApiPropertyOptional() @ApiPropertyOptional()

View file

@ -15,6 +15,7 @@ export class RevisionMetadataDto extends BaseDto {
* ID of this revision * ID of this revision
* @example 13 * @example 13
*/ */
@Type(() => Number)
@IsNumber() @IsNumber()
@ApiProperty() @ApiProperty()
id: Revision['id']; id: Revision['id'];
@ -41,7 +42,7 @@ export class RevisionMetadataDto extends BaseDto {
* Does not include anonymous users * Does not include anonymous users
*/ */
@IsString() @IsString()
@ApiProperty() @ApiProperty({ isArray: true, type: String })
authorUsernames: string[]; authorUsernames: string[];
/** /**
@ -75,6 +76,6 @@ export class RevisionMetadataDto extends BaseDto {
*/ */
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
@ApiProperty() @ApiProperty({ isArray: true, type: String })
tags: string[]; tags: string[];
} }

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsString, ValidateNested } from 'class-validator'; import { IsString, ValidateNested } from 'class-validator';
import { EditDto } from './edit.dto'; import { EditDto } from './edit.dto';
@ -28,7 +29,8 @@ export class RevisionDto extends RevisionMetadataDto {
/** /**
* All edit objects which are used in the revision. * All edit objects which are used in the revision.
*/ */
@ValidateNested() @Type(() => EditDto)
@ApiProperty() @ValidateNested({ each: true })
@ApiProperty({ isArray: true, type: EditDto })
edits: EditDto[]; edits: EditDto[];
} }

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsLowercase, IsString } from 'class-validator'; import { IsLowercase, IsString } from 'class-validator';
import { BaseDto } from '../utils/base.dto.'; import { BaseDto } from '../utils/base.dto.';
@ -14,6 +15,7 @@ export class UserInfoDto extends BaseDto {
* The username * The username
* @example "john.smith" * @example "john.smith"
*/ */
@Type(() => String)
@IsString() @IsString()
@IsLowercase() @IsLowercase()
@ApiProperty() @ApiProperty()