Skip to content

derive and add a service to context post-validation #703

Closed Answered by crishoj
crishoj asked this question in Q&A
Discussion options

You must be logged in to vote

Found the answer — just use resolve!

new Elysia()
    .group('devices/:id', {params: t.Object({id: t.Numeric()})}, app => app
        .resolve(({params: {id}}) => ({device: getDevice(id)}))
        .post('devices/:id/connect', ({device}) => device.connect())
        .post('devices/:id/disconnect', ({device}) => device.disconnect())
        .post('devices/:id/start', ({device}) => device.start())
        .post('devices/:id/stop', ({device}) => device.stop()))

Elysia is elegant ✨

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by crishoj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant