Skip to content

Commit

Permalink
Use param objects
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Sep 11, 2023
1 parent ae3f29d commit 0864d96
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/controllers/getStars.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ module.exports = {
"X-Content-Type-Options": "nosniff"
}
},
params(req, context) {
return {
auth: query.auth(req)
};
params: {
auth: (context, req) => { return context.query.auth(req); }
},

/**
Expand Down
10 changes: 4 additions & 6 deletions src/controllers/getThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ module.exports = {
"X-Content-Type-Options": "nosniff"
}
},
params(req, context) {
return {
page: context.query.page(req),
sort: context.query.sort(req),
direction: context.query.dir(req)
};
params: {
page: (context, req) => { return context.query.page(req); },
sort: (context, req) => { return context.query.sort(req); },
direction: (context, req) => { return context.query.dir(req); }
},

/**
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/getThemesFeatured.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ module.exports = {
"X-Content-Type-Options": "nosniff"
}
},
params(req, context) {
params: {
// Currently we don't seem to utilize any query parameters here.
// We likely want to make this match whatever is used in getPackagesFeatured.js
return {};
},
async logic(params, context) {
const col = await context.database.getFeaturedThemes();
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/getUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ module.exports = {
"X-Content-Type-Options": "nosniff"
}
},
params(req, context) {
return {};
},
params: {},

/**
* @async
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/getUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ module.exports = {
"Access-Control-Allow-Credentials": true
}
},
params(req, context) {
return {
auth: context.query.auth(req)
};
params: {
auth: (context, req) => { return context.query.auth(req); }
},
preLogic(req, res, context) {
res.header("Access-Control-Allow-Methods", "GET");
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/getUsersLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ module.exports = {
"X-Content-Type-Options": "nosniff"
}
},
params(req, context) {
return {
login: context.query.login(req)
};
params: {
login: (context, req) => { return context.query.login(req); }
},

/**
Expand Down
18 changes: 15 additions & 3 deletions src/setupEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ for (const node of endpoints) {
switch(node.endpoint.method) {
case "GET":
app.get(path, limiter, async (req, res) => {
let params = node.params(req, context);
let params = {};

for (const param in node.params) {
params[param] = node.params[param](context, req);
}

if (typeof node.preLogic === "function") {
node.preLogic(req, res, context);
Expand All @@ -104,7 +108,11 @@ for (const node of endpoints) {
});
case "POST":
app.post(path, limiter, async (req, res) => {
let params = node.params(req, context);
let params = {};

for (const param in node.params) {
params[param] = node.params[param](context, req);
}

if (typeof node.preLogic === "function") {
node.preLogic(req, res, context);
Expand All @@ -123,7 +131,11 @@ for (const node of endpoints) {
});
case "DELETE":
app.delete(path, limiter, async (req, res) => {
let params = node.params(req, context);
let params = {};

for (const param in node.params) {
params[param] = node.params[param](context, req);
}

if (typeof node.preLogic === "function") {
node.preLogic(req, res, context);
Expand Down

0 comments on commit 0864d96

Please sign in to comment.