Fix of backend validation problems. #8
@@ -11,6 +11,7 @@ import {
|
|||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||||
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
||||||
import { ApiKeysService } from "./api-keys.service";
|
import { ApiKeysService } from "./api-keys.service";
|
||||||
|
import { CreateApiKeyDto } from "./dto/create-api-key.dto";
|
||||||
|
|
||||||
@Controller("api-keys")
|
@Controller("api-keys")
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@@ -20,13 +21,12 @@ export class ApiKeysController {
|
|||||||
@Post()
|
@Post()
|
||||||
create(
|
create(
|
||||||
@Req() req: AuthenticatedRequest,
|
@Req() req: AuthenticatedRequest,
|
||||||
@Body("name") name: string,
|
@Body() createApiKeyDto: CreateApiKeyDto,
|
||||||
@Body("expiresAt") expiresAt?: string,
|
|
||||||
) {
|
) {
|
||||||
return this.apiKeysService.create(
|
return this.apiKeysService.create(
|
||||||
req.user.sub,
|
req.user.sub,
|
||||||
name,
|
createApiKeyDto.name,
|
||||||
expiresAt ? new Date(expiresAt) : undefined,
|
createApiKeyDto.expiresAt ? new Date(createApiKeyDto.expiresAt) : undefined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
backend/src/api-keys/dto/create-api-key.dto.ts
Normal file
12
backend/src/api-keys/dto/create-api-key.dto.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { IsDateString, IsNotEmpty, IsOptional, IsString, MaxLength } from "class-validator";
|
||||||
|
|
||||||
|
export class CreateApiKeyDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@MaxLength(128)
|
||||||
|
name!: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
expiresAt?: string;
|
||||||
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
import { IsNotEmpty, IsOptional, IsString } from "class-validator";
|
import { IsNotEmpty, IsOptional, IsString, MaxLength } from "class-validator";
|
||||||
|
|
||||||
export class CreateCategoryDto {
|
export class CreateCategoryDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(64)
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@MaxLength(255)
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@MaxLength(512)
|
||||||
iconUrl?: string;
|
iconUrl?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
IsUUID,
|
IsUUID,
|
||||||
|
MaxLength,
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
|
|
||||||
export enum ContentType {
|
export enum ContentType {
|
||||||
@@ -19,14 +20,17 @@ export class CreateContentDto {
|
|||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(255)
|
||||||
title!: string;
|
title!: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(512)
|
||||||
storageKey!: string;
|
storageKey!: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(128)
|
||||||
mimeType!: string;
|
mimeType!: string;
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@@ -39,5 +43,6 @@ export class CreateContentDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
|
@MaxLength(64, { each: true })
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
IsUUID,
|
IsUUID,
|
||||||
|
MaxLength,
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { ContentType } from "./create-content.dto";
|
import { ContentType } from "./create-content.dto";
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ export class UploadContentDto {
|
|||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(255)
|
||||||
title!: string;
|
title!: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -20,6 +22,8 @@ export class UploadContentDto {
|
|||||||
categoryId?: string;
|
categoryId?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
|
@MaxLength(64, { each: true })
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IsEnum, IsOptional, IsString, IsUUID } from "class-validator";
|
import { IsEnum, IsOptional, IsString, IsUUID, MaxLength } from "class-validator";
|
||||||
|
|
||||||
export enum ReportReason {
|
export enum ReportReason {
|
||||||
INAPPROPRIATE = "inappropriate",
|
INAPPROPRIATE = "inappropriate",
|
||||||
@@ -21,5 +21,6 @@ export class CreateReportDto {
|
|||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@MaxLength(1000)
|
||||||
description?: string;
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { IsNotEmpty, IsString } from "class-validator";
|
import { IsNotEmpty, IsString, MaxLength } from "class-validator";
|
||||||
|
|
||||||
export class UpdateConsentDto {
|
export class UpdateConsentDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(16)
|
||||||
termsVersion!: string;
|
termsVersion!: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@MaxLength(16)
|
||||||
privacyVersion!: string;
|
privacyVersion!: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user