Skip to content

Commit

Permalink
added a backend check where if currentpage or pagesize isnt set for l…
Browse files Browse the repository at this point in the history
…ist models it will return the full list
  • Loading branch information
ARADDCC002 committed Jan 10, 2025
1 parent 5dda340 commit b339ea5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/routes/v2/model/getModelsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const getModelsSearch = [
async (req: Request, res: Response<GetModelsResponse>) => {
req.audit = AuditInfo.SearchModels
const {
query: { kind, libraries, filters, search, task, allowTemplating, schemaId, currentPage = 1, pageSize = 10 },
query: { kind, libraries, filters, search, task, allowTemplating, schemaId, currentPage, pageSize },
} = parse(req, getModelsSearchSchema)

const foundModels = await searchModels(
Expand Down
7 changes: 5 additions & 2 deletions backend/src/services/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export async function searchModels(
task?: string,
allowTemplating?: boolean,
schemaId?: string,
currentPage: number = 0,
pageSize: number = 10,
currentPage?: number,
pageSize?: number,
): Promise<ModelSearchResult> {
const query: any = {}

Expand Down Expand Up @@ -181,6 +181,9 @@ export async function searchModels(
// match the query first, and then filter them based on pagination.
const auths = await authorisation.models(user, results, ModelAction.View)
const authorisedResults = results.filter((_, i) => auths[i].success)
if (!pageSize || !currentPage) {
return { results: authorisedResults, totalEntries: authorisedResults.length }
}
const paginatedResults = authorisedResults.slice((currentPage - 1) * pageSize, currentPage * pageSize)
return { results: paginatedResults, totalEntries: authorisedResults.length }
}
Expand Down

0 comments on commit b339ea5

Please sign in to comment.