Compare commits

...

3 Commits

Author SHA1 Message Date
8ee5410c91 Refactor files controller imports and rearrange decorators
Reorganized import statements for cleaner structure and added a missing import for CreateFileTypeDto. Adjusted the placement of UseGuards decorators to maintain consistency across methods.
2024-10-15 11:27:47 +02:00
e7830095b3 Add CreateFileTypeDto class to files.dto.ts
Introduced a new DTO class named CreateFileTypeDto in files.dto.ts for future implementations. The class currently has no properties defined, marked with a TODO comment for subsequent development.
2024-10-15 11:23:13 +02:00
055c48dbf9 Add endpoints for file types management
Introduced new endpoints to handle file types: fetching all types, adding a new type, and deleting a type. These additions include necessary guards and parameter parsing for robust API functionality.
2024-10-15 11:23:04 +02:00
2 changed files with 30 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { IncomingMessage } from "node:http";
import {
BadRequestException,
Body,
Controller,
DefaultValuePipe,
Delete,
@@ -9,6 +10,7 @@ import {
HttpStatus,
Param,
ParseIntPipe,
ParseUUIDPipe,
Post,
Query,
Req,
@@ -18,6 +20,7 @@ import {
StreamableFile,
UseGuards,
} from "@nestjs/common";
import { CreateFileTypeDto } from "apps/backend/src/app/files/files.dto";
import { AdminGuard, InsertAdminState } from "../auth/auth.guard";
import { FilesService } from "./files.service";
@@ -25,8 +28,8 @@ import { FilesService } from "./files.service";
export class FilesController {
constructor(private readonly filesService: FilesService) {}
@UseGuards(InsertAdminState)
@HttpCode(HttpStatus.OK)
@UseGuards(InsertAdminState)
@Post("new")
async saveFile(@Req() req: IncomingMessage, @Res() res: Response) {
let fileBuffer: Buffer = Buffer.from([]);
@@ -123,10 +126,30 @@ export class FilesController {
return await this.filesService.get(fileId);
}
@UseGuards(AdminGuard)
@HttpCode(HttpStatus.OK)
@UseGuards(AdminGuard)
@Delete(":fileId")
async deleteFile(@Param("fileId") fileId: string) {
async deleteFile(@Param("fileId", ParseUUIDPipe) fileId: string) {
return await this.filesService.deleteFile(fileId);
}
@HttpCode(HttpStatus.FOUND)
@Get("types")
async getTypes() {
//TODO
}
@HttpCode(HttpStatus.CREATED)
@UseGuards(AdminGuard)
@Post("types/new")
async newType(@Body() body: CreateFileTypeDto) {
//TODO
}
@HttpCode(HttpStatus.ACCEPTED)
@UseGuards(AdminGuard)
@Delete("types/:typeId")
async delType(@Param(":typeId", ParseUUIDPipe) typeId: string) {
//TODO
}
}

View File

@@ -16,3 +16,7 @@ export class CreateFilesDto {
@IsUUID()
groupId: string;
}
export class CreateFileTypeDto {
//TODO
}