From 7876bc2c38ec4a74e4c8cfed59cf192115760824 Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 8 Oct 2024 16:11:34 +0200 Subject: [PATCH] Revise file search logic for machine service Updated the file search functionality to include a search field that filters files by name and added pagination support. This enhances the API by providing more flexible querying and making it easier to handle large datasets. --- .../src/app/machines/machines.service.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/backend/src/app/machines/machines.service.ts b/apps/backend/src/app/machines/machines.service.ts index ca84f31..1bad6fc 100644 --- a/apps/backend/src/app/machines/machines.service.ts +++ b/apps/backend/src/app/machines/machines.service.ts @@ -177,14 +177,15 @@ export class MachinesService { } /** - * Finds files associated with a specific machine. + * Finds files associated with a specific machine based on a search field, + * and returns a limited set of results with an offset for pagination. * * @param {number} limit - The maximum number of files to return. - * @param {number} offset - The number of files to skip before starting to return results. - * @param {string} searchField - The field to search within for files. - * @param {string} machineId - The ID of the machine to find files for. - * @returns {Promise>} A promise that resolves to an array of files associated with the specified machine. - * @throws {NotFoundException} If the machine ID is not found. + * @param {number} offset - The offset for pagination. + * @param {string} searchField - The search query to filter files by name. + * @param {string} machineId - The unique identifier of the machine to find files for. + * @returns {Promise} A promise that resolves to an array of files associated with the specified machine. + * @throws {NotFoundException} If the specified machine id is not found. */ async findFilesForMachine( limit: number, @@ -212,7 +213,13 @@ export class MachinesService { .where(eq(FilesForMachinesTable.machineId, machineId)) .limit(limit) .offset(offset) - .leftJoin(FilesTable, eq(FilesTable.uuid, FilesForMachinesTable.fileId)) + .leftJoin( + FilesTable, + and( + eq(FilesTable.uuid, FilesForMachinesTable.fileId), + ilike(FilesTable.fileName, String(`%${searchField}%`)), + ), + ) .prepare("findFilesForMachineId") .execute(); }