Skip to content

Commit c587adc

Browse files
authored
Add filter options to protocol path read route (#166)
1 parent 1077722 commit c587adc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/http-api.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,19 @@ export class HttpApi {
150150
return res.status(400).send('protocol path is required');
151151
}
152152

153-
const protocolPath = req.params[0].replace(leadTailSlashRegex, '');
154-
const protocol = req.params.protocol;
153+
const queryOptions = { filter: {} } as any;
154+
for (const param in req.query) {
155+
const keys = param.split('.');
156+
const lastKey = keys.pop();
157+
const lastLevelObject = keys.reduce((obj, key) => obj[key] = obj[key] || {}, queryOptions)
158+
lastLevelObject[lastKey] = req.query[param];
159+
}
160+
161+
queryOptions.filter.protocol = req.params.protocol;
162+
queryOptions.filter.protocolPath = req.params[0].replace(leadTailSlashRegex, '');
155163

156164
const query = await RecordsQuery.create({
157-
filter: {
158-
protocol,
159-
protocolPath,
160-
},
165+
filter: queryOptions.filter,
161166
pagination: { limit: 1 },
162167
dateSort: DateSort.PublishedDescending
163168
});

0 commit comments

Comments
 (0)