Skip to content

Commit

Permalink
Merge pull request #15 from scimmyjs/issue/13-pagination-constraint-p…
Browse files Browse the repository at this point in the history
…arsing

Add: casting of pagination query parameters from strings to numbers
  • Loading branch information
sleelin authored Feb 28, 2024
2 parents ef68965 + 91a7d38 commit 9cb985f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class SCIMMYRouters extends Router {
// Make sure SCIM JSON is decoded in request body
this.use(express.json({type: "application/scim+json", limit: SCIMMY.Config.get()?.bulk?.maxPayloadSize ?? "1mb"}));

// Listen for first request to determine basepath for all resource types
// Listen for incoming requests to determine basepath for all resource types
this.use("/", (req, res, next) => {
res.setHeader("Content-Type", "application/scim+json");
SCIMMY.Resources.Schema.basepath(req.baseUrl);
Expand All @@ -99,6 +99,18 @@ export default class SCIMMYRouters extends Router {
}
});

// Cast pagination query parameters from strings to numbers...
this.use(({query}, res, next) => {
for (let param of ["startIndex", "count"]) {
// ...but only if they were defined, were strings, and are valid as numbers
if (!!query[param] && typeof query[param] === "string" && !Number.isNaN(+query[param])) {
query[param] = +query[param];
}
}

next();
});

// Register core service provider endpoints
this.use(new Schemas());
this.use(new ResourceTypes());
Expand Down

0 comments on commit 9cb985f

Please sign in to comment.