mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
refactor controller class
This commit is contained in:
parent
368d0252a4
commit
47d4149923
@ -1,15 +1,18 @@
|
|||||||
class Controller {
|
class Controller {
|
||||||
constructor(key, exec, params) {
|
constructor(payload) {
|
||||||
this.key = key ?? "controller"
|
this.payload = {...payload}
|
||||||
this.params = { ...params }
|
|
||||||
|
|
||||||
if (typeof exec === "function") {
|
return this
|
||||||
this.exec = exec
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exec(req, res, next) {
|
exec = async (req, res, next) => {
|
||||||
res.json(`empty response`)
|
if (typeof this.payload.exec === "function") {
|
||||||
|
try {
|
||||||
|
await this.payload.exec (req, res, next)
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(500).json({ error: error.message, endpoint: this.payload.route })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user