From a8addc5aaaecca292b7d2bdc3a848a795329a3b4 Mon Sep 17 00:00:00 2001 From: Autumn Date: Tue, 12 May 2026 18:31:59 +0100 Subject: [api] added device toggling API route --- src/routes/api.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/routes/api.ts (limited to 'src/routes') 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 -- cgit v1.3