aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api.ts
blob: 84a0f5dfd27495ceb4d4f6cbf48a78276fcc2648 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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