From 310a806c8743428a0cb4d67757cc0acc647b5e45 Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 30 Sep 2024 14:33:18 +0200 Subject: [PATCH] Remove file service tests and update get method parameter Removed the `files.service.spec.ts` test file as it is no longer required. Updated the `get` method parameter in `files.service.ts` to use `fileId` instead of `checksum`, and adjusted the related logic for consistency. --- .../src/app/files/files.service.spec.ts | 18 -------------- apps/backend/src/app/files/files.service.ts | 24 +++++++++---------- 2 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 apps/backend/src/app/files/files.service.spec.ts diff --git a/apps/backend/src/app/files/files.service.spec.ts b/apps/backend/src/app/files/files.service.spec.ts deleted file mode 100644 index 38817b2..0000000 --- a/apps/backend/src/app/files/files.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import { FilesService } from "./files.service"; - -describe("FilesService", () => { - let service: FilesService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [FilesService], - }).compile(); - - service = module.get(FilesService); - }); - - it("should be defined", () => { - expect(service).toBeDefined(); - }); -}); diff --git a/apps/backend/src/app/files/files.service.ts b/apps/backend/src/app/files/files.service.ts index 4bcc90f..8096be8 100644 --- a/apps/backend/src/app/files/files.service.ts +++ b/apps/backend/src/app/files/files.service.ts @@ -12,25 +12,25 @@ export class FilesService { private readonly database: DbService, ) {} - /** - * Fetches a file and its information based on the provided checksum. - * - * @param {string} checksum - The unique identifier for the file. - * @return {Promise>} An object containing the stream of the file, its information, and additional data. - * @throws {NotFoundException} If the file with the given checksum is not found. - */ - public async get(checksum: string): Promise> { + /** + * Retrieves a file and its related information from the database and associated storage. + * + * @param fileId The unique identifier for the file to be retrieved. + * @return A promise that resolves to an object containing the streamable file and additional file information. + * @throws NotFoundException if the file does not exist in the database. + */ + public async get(fileId: string): Promise> { const foundFiles = await this.database .use() .select() .from(FilesTable) - .where(eq(FilesTable.checksum, checksum)) - .prepare("getFileFromChecksum") + .where(eq(FilesTable.uuid, fileId)) + .prepare("getFileFromId") .execute(); if (foundFiles.length === 0) - throw new NotFoundException("File with checksum not found", { - description: `checksum : ${checksum}` + throw new NotFoundException("File not found", { + description: `Identifier : ${fileId}` }); if (foundFiles.length > 1)