diff options
| author | Autumn <git@autumnfo.rest> | 2026-05-12 18:31:59 +0100 |
|---|---|---|
| committer | Autumn <git@autumnfo.rest> | 2026-05-12 18:31:59 +0100 |
| commit | a8addc5aaaecca292b7d2bdc3a848a795329a3b4 (patch) | |
| tree | 6c28cdb7f0644708b0a66fe3062b7cbcbc549547 /src/routes | |
| parent | 56ccdf34d5a820fbdabb3674b2392b9d1e2b1ecf (diff) | |
[api] added device toggling API route
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 |
