All files / src/api/routes devices.ts

0% Statements 0/9
100% Branches 0/0
100% Functions 0/0
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147                                                                                                                                                                                                                                                                                                     
import express from "express";
import { DeviceController } from "../controllers/deviceController";
 
const router = express.Router();
const deviceController = new DeviceController();
 
/**
 * @swagger
 * /api/devices:
 *   get:
 *     tags:
 *       - Devices
 *     summary: Get all devices, optionally filtered by various parameters
 *     description: Retrieve a list of devices. You can filter the devices by type, name, timestamp, or location.
 *     parameters:
 *       - in: query
 *         name: type
 *         schema:
 *           type: string
 *           enum: [thingy52, tag, beacon]
 *         description: Filter devices by type (e.g., thingy, tag, beacon)
 *       - in: query
 *         name: name
 *         schema:
 *           type: string
 *         description: Filter devices by name (case-insensitive)
 *       - in: query
 *         name: floor_id
 *         schema:
 *           type: integer
 *         description: Filter devices by floor ID
 *       - in: query
 *         name: x
 *         schema:
 *           type: number
 *         description: Filter devices by x-coordinate
 *       - in: query
 *         name: y
 *         schema:
 *           type: number
 *         description: Filter devices by y-coordinate
 *       - in: query
 *         name: macAddress
 *         schema:
 *           type: string
 *         description: Filter devices by MAC address
 *       - in: query
 *         name: deactivate
 *         schema:
 *           type: boolean
 *         description: Filter devices by deactivation status
 *     responses:
 *       200:
 *         description: A list of devices
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 $ref: '#/components/schemas/Device'
 *       500:
 *         description: Failed to fetch devices, Internal server error
 */
router.get("/", deviceController.getDevices);
 
/**
 * @swagger
 * /api/devices:
 *   put:
 *     tags:
 *       - Devices
 *     summary: Update a device
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/Device'
 *     responses:
 *       200:
 *         description: Device created successfully
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Device'
 *       400:
 *         description: Invalid request body
 *       500:
 *         description: Failed to create device, Internal server error
 */
router.put("/", deviceController.updateDevice);
 
/**
 * @swagger
 * /api/devices:
 *   post:
 *     tags:
 *       - Devices
 *     summary: Create a new device
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/Device'
 *     responses:
 *       200:
 *         description: Device created successfully
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Device'
 *       400:
 *         description: Invalid request body
 *       500:
 *         description: Failed to create device, Internal server error
 */
router.post("/", deviceController.createDevice);
 
/**
 * @swagger
 * /api/devices/{macAddress}:
 *   delete:
 *     tags:
 *       - Devices
 *     summary: Delete a device by MAC address
 *     parameters:
 *       - in: path
 *         name: macAddress
 *         required: true
 *         schema:
 *           type: string
 *         description: The MAC address of the device
 *     responses:
 *       200:
 *         description: Device deleted successfully
 *       404:
 *         description: Device not found
 *       400:
 *         description: Mac address is required
 *       500:
 *         description: Failed to delete device, Internal server error
 */
router.delete("/:macAddress", deviceController.deleteDevice);
 
 
export default router;