Skip to content

Commit

Permalink
Add filter options to protocol path read route
Browse files Browse the repository at this point in the history
  • Loading branch information
csuwildcat committed Sep 10, 2024
1 parent 1077722 commit 578e954
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ export class HttpApi {
return res.status(400).send('protocol path is required');
}

const protocolPath = req.params[0].replace(leadTailSlashRegex, '');
const protocol = req.params.protocol;
const queryOptions = { filter: {} } as any;
for (const param in req.query) {
const keys = param.split('.');
const lastKey = keys.pop();
const lastLevelObject = keys.reduce((obj, key) => obj[key] = obj[key] || {}, queryOptions)
lastLevelObject[lastKey] = req.query[param];
}

queryOptions.filter.protocol = req.params.protocol;
queryOptions.filter.protocolPath = req.params[0].replace(leadTailSlashRegex, '');

const query = await RecordsQuery.create({
filter: {
protocol,
protocolPath,
},
filter: queryOptions.filter,
pagination: { limit: 1 },
dateSort: DateSort.PublishedDescending
});
Expand Down

0 comments on commit 578e954

Please sign in to comment.