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.
This commit is contained in:
Mathis H (Avnyr) 2024-09-30 14:33:18 +02:00
parent 4d7ae970bc
commit 310a806c87
Signed by: Mathis
GPG Key ID: DD9E0666A747D126
2 changed files with 12 additions and 30 deletions

View File

@ -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>(FilesService);
});
it("should be defined", () => {
expect(service).toBeDefined();
});
});

View File

@ -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<IFileWithInformation<object>>} 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<IFileWithInformation<object>> {
/**
* 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<IFileWithInformation<object>> {
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)