Skip to content

Commit 75e00f0

Browse files
Daev MithranDaev Mithran
authored andcommitted
fix params in agncty client
1 parent 1dc8024 commit 75e00f0

File tree

5 files changed

+310
-249
lines changed

5 files changed

+310
-249
lines changed

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class App {
409409
app.post('/record/publish', AgntcyController.recordPublishValidator, new AgntcyController().publishRecord);
410410
app.get('/record/search', AgntcyController.recordSearchValidator, new AgntcyController().searchRecord);
411411
app.get('/record/:cid', AgntcyController.recordGetValidator, new AgntcyController().getRecord);
412-
412+
413413
// 404 for all other requests
414414
app.all('*', (_req, res) => res.status(StatusCodes.BAD_REQUEST).send('Bad request'));
415415
}

src/controllers/api/agntcy.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export class AgntcyController {
2020
// Validators
2121
public static recordPublishValidator = [
2222
check('data').exists().withMessage('data field is required').bail(),
23-
check('data.name').exists().withMessage('name is required').isString().withMessage('name must be a string').bail(),
23+
check('data.name')
24+
.exists()
25+
.withMessage('name is required')
26+
.isString()
27+
.withMessage('name must be a string')
28+
.bail(),
2429
check('data.version')
2530
.exists()
2631
.withMessage('version is required')
@@ -62,11 +67,7 @@ export class AgntcyController {
6267
.withMessage('Invalid record type')
6368
.bail(),
6469
query('page').optional().isInt({ min: 1 }).withMessage('page must be a positive integer').bail(),
65-
query('limit')
66-
.optional()
67-
.isInt({ min: 1, max: 100 })
68-
.withMessage('limit must be between 1 and 100')
69-
.bail(),
70+
query('limit').optional().isInt({ min: 1, max: 100 }).withMessage('limit must be between 1 and 100').bail(),
7071
];
7172

7273
public static recordGetValidator = [
@@ -263,12 +264,10 @@ export class AgntcyController {
263264

264265
try {
265266
// Set defaults for pagination
266-
const { page = 1, limit = 20 } = request.query as SearchRecordQuery;
267+
const { page = 1, limit = 20 } = request.query as SearchRecordQuery;
267268

268269
// Search directory
269-
const results = await agntcyService.search(
270-
response.locals.customer,
271-
{
270+
const results = await agntcyService.search(response.locals.customer, {
272271
...query,
273272
page,
274273
limit,
@@ -284,7 +283,6 @@ export class AgntcyController {
284283
total: results.total,
285284
total_pages: Math.ceil(results.total / limit),
286285
},
287-
filters_applied: this.getAppliedFilters(query),
288286
} satisfies SearchRecordResponseBody);
289287
} catch (error) {
290288
return response.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
@@ -406,4 +404,4 @@ export class AgntcyController {
406404

407405
return filters;
408406
}
409-
}
407+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { AuthRuleProvider } from '../auth-rule-provider.js';
22

33
export class RecordAuthProvider extends AuthRuleProvider {
4-
constructor() {
5-
super();
6-
this.registerRule('/record/search', 'GET', 'read:account', { skipNamespace: true });
7-
this.registerRule('/record/publish', 'POST', 'create:account', { skipNamespace: true });
8-
this.registerRule('/record/:cid', 'GET', 'read:account', { skipNamespace: true });
9-
}
4+
constructor() {
5+
super();
6+
this.registerRule('/record/search', 'GET', 'read:account', { skipNamespace: true });
7+
this.registerRule('/record/publish', 'POST', 'create:account', { skipNamespace: true });
8+
this.registerRule('/record/(.*)', 'GET', 'read:account', { skipNamespace: true });
9+
}
1010
}

0 commit comments

Comments
 (0)