how can I access./ manhour
without writing path parameters?
in addition, I would like to ask, do not directly operate the database, only interface forwarding,koa2
can have the concept ofmodel
?
now I am using the chainedrouter.get ("/ manhour", controllers.manhour.get,
) to insert the data into the page, but the page cannot always have only one interface, and it is confusing to write too much, so I would like to ask if there is amodel
concept
routes/api.js
router.get("/api/manhour/:userid/:year/:weeks", controllers.manhour.get)
routes/manhour.js
router.get("/manhour", controllers.manhour.get, async (ctx, next) => {
await ctx.render("manhour", {
data: ctx.state.data,
})
})
controllers/manhour.js
async function get(ctx, next) {
const { userid, year, weeks } = ctx.params
const params = {
userid,
year,
weeks,
}
await axios.get(getWorkingTimeList, { params })
.then(res => {
if (res.status === 200) {
ctx.state.code = 0
ctx.state.data = res.data
} else {
ctx.state.code = -1
ctx.state.data = {}
}
})
await next()
}
module.exports = {
get,
}