diff --git a/apps/backend/src/app/files/files.controller.ts b/apps/backend/src/app/files/files.controller.ts index 2381a41..62ad2f9 100644 --- a/apps/backend/src/app/files/files.controller.ts +++ b/apps/backend/src/app/files/files.controller.ts @@ -2,7 +2,7 @@ import { IncomingMessage } from "node:http"; import { BadRequestException, Controller, - DefaultValuePipe, + DefaultValuePipe, Delete, Get, HttpCode, HttpStatus, @@ -15,9 +15,9 @@ import { Res, Response, StreamableFile, - UseGuards, -} from "@nestjs/common"; -import { InsertAdminState } from "../auth/auth.guard"; + UseGuards +} from '@nestjs/common'; +import { AdminGuard, InsertAdminState } from '../auth/auth.guard'; import { FilesService } from "./files.service"; @Controller("files") @@ -121,4 +121,11 @@ export class FilesController { async getFile(@Param("fileId") fileId: string) { return await this.filesService.get(fileId); } + + @UseGuards(AdminGuard) + @HttpCode(HttpStatus.OK) + @Delete(":fileId") + async deleteFile(@Param("fileId") fileId: string) { + return await this.filesService.deleteFile(fileId); + } } diff --git a/apps/backend/src/app/files/files.service.ts b/apps/backend/src/app/files/files.service.ts index 0dbeb3f..a0ee54f 100644 --- a/apps/backend/src/app/files/files.service.ts +++ b/apps/backend/src/app/files/files.service.ts @@ -68,6 +68,12 @@ export class FilesService { } //TODO DELETE FILE + public async deleteFile(fileId: string) { + //get checksum for fileId + //check if multiple entry for checksum + //if that the case then only remove the entry in database relative to fileId. + //if there is one only entry then remove the file from the storage and the database. + } /** * Searches for files in the database using the specified search field, limit, and offset.