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.
This commit is contained in:
parent
84d6743863
commit
7876bc2c38
@ -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<Array<Object>>} 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<Array>} 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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user