diff options
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/api.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/routes/api.ts b/src/routes/api.ts new file mode 100644 index 0000000..84a0f5d --- /dev/null +++ b/src/routes/api.ts @@ -0,0 +1,33 @@ +// +// ~~~ api routing +// + +// imports +import { Router } from "express" +import { setState } from "@lib/helpers/device.ts" + +// setup router +const router = Router() + +// toggle device +router.get("/device/:id/toggle", async (req, res) => { + + const device = req.params.id + const state = await setState(device, "TOGGLE") + + console.debug(`-> toggling ${device}`) + + if (state === false) { + + console.error(`!> cannot toggle ${device}`) + res.sendStatus(500) + + } else { + + res.sendStatus(200) + + } +}) + +// export router +export default router |
