33 lines
998 B
TypeScript
33 lines
998 B
TypeScript
import express, { Request, Response } from "express";
|
|
import { container } from "tsyringe";
|
|
import { WifiLocationService } from "../services/wifiLocationService";
|
|
|
|
const wifiLocationService = container.resolve(WifiLocationService);
|
|
const router = express.Router();
|
|
|
|
router.get("/", async (req: Request, res: Response) => {
|
|
try {
|
|
const wifiLocations = await wifiLocationService.getAllWifiLocations();
|
|
res.status(200).json(wifiLocations);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: "Error retrieving wifi location" });
|
|
}
|
|
});
|
|
|
|
router.delete("/:id", async (req: Request, res: Response) => {
|
|
try {
|
|
const { id } = req.params;
|
|
const deleted = await wifiLocationService.deleteWifiLocation(id);
|
|
if (!deleted) {
|
|
res.status(404).json({ error: "Wifi Location not found" });
|
|
return;
|
|
}
|
|
res.status(204).send();
|
|
} catch (error) {
|
|
res.status(500).json({ error: "Error deleting wifi location" });
|
|
}
|
|
});
|
|
|
|
export default router;
|