From e37684760ac87f47a3dc3383f66012b68990124f Mon Sep 17 00:00:00 2001 From: srgooglo Date: Thu, 26 Jan 2023 20:55:01 +0100 Subject: [PATCH] fix function transformation --- .../TestController/endpoints/objectEndpoint.js | 9 +++++++++ src/server/classes/controller/index.js | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 example_server/src/controllers/TestController/endpoints/objectEndpoint.js diff --git a/example_server/src/controllers/TestController/endpoints/objectEndpoint.js b/example_server/src/controllers/TestController/endpoints/objectEndpoint.js new file mode 100644 index 0000000..3328691 --- /dev/null +++ b/example_server/src/controllers/TestController/endpoints/objectEndpoint.js @@ -0,0 +1,9 @@ +export default { + method: "get", + route: "/withoutClass", + fn: async (req, res) => { + return res.json({ + message: "Im an object endpoint", + }) + } +} \ No newline at end of file diff --git a/src/server/classes/controller/index.js b/src/server/classes/controller/index.js index 85074b7..f57c323 100644 --- a/src/server/classes/controller/index.js +++ b/src/server/classes/controller/index.js @@ -60,10 +60,8 @@ module.exports = class Controller { this.customHandler = objEndpoint.customHandler } } - } - - // Handle endpoint transformation as a function - if (typeof endpoint === "function") { + } else if (typeof endpoint === "function") { + // Handle endpoint transformation as a function const endpointFn = endpoint endpoint = class extends Endpoint { @@ -122,6 +120,8 @@ module.exports = class Controller { return (...args) => new Promise(async (resolve, reject) => { try { + console.log(fn) + const result = await fn(...args) return resolve(result)