import { ok, asyncHandler } from '../../utils/http.js'; import * as service from './service.js'; export const getDevices = asyncHandler(async (req, res) => ok(res, await service.listDevices(req.query))); export const getDevice = asyncHandler(async (req, res) => ok(res, await service.getDevice(Number(req.params.id)))); export const putDevice = asyncHandler(async (req, res) => ok(res, await service.updateDevice(Number(req.params.id), req.body, req.currentUser))); export const getDashboard = asyncHandler(async (req, res) => ok(res, await service.getDashboard())); export const getSoftware = asyncHandler(async (req, res) => ok(res, await service.listSoftware(req.query.q, req.query.all))); export const getSoftwareDevices = asyncHandler(async (req, res) => ok(res, await service.devicesWithSoftware(String(req.query.name || '')))); export const getRaw = asyncHandler(async (req, res) => { const { full, file } = await service.getRaw(Number(req.params.id)); res.download(full, file); }); export const getTokens = asyncHandler(async (req, res) => ok(res, await service.listTokens())); export const postToken = asyncHandler(async (req, res) => ok(res, await service.createToken(req.body.label, req.currentUser), 201)); export const getTokenSecret = asyncHandler(async (req, res) => ok(res, await service.revealToken(Number(req.params.id), req.currentUser))); export const patchToken = asyncHandler(async (req, res) => ok(res, await service.setTokenActive(Number(req.params.id), !!req.body.isActive, req.currentUser))); export const deleteToken = asyncHandler(async (req, res) => ok(res, await service.removeToken(Number(req.params.id), req.currentUser))); export const getAccess = asyncHandler(async (req, res) => ok(res, await service.getAccess(req.currentUser))); export const getViewers = asyncHandler(async (req, res) => ok(res, await service.listViewers())); export const postViewer = asyncHandler(async (req, res) => ok(res, await service.addViewer(Number(req.body.userId), req.currentUser), 201)); export const deleteViewer = asyncHandler(async (req, res) => ok(res, await service.removeViewer(Number(req.params.userId), req.currentUser))); export const postCpuYear = asyncHandler(async (req, res) => ok(res, await service.fetchCpuYear(Number(req.params.id), req.currentUser)));