"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = require("express"); const prisma_1 = __importDefault(require("../lib/prisma")); const auth_1 = require("../middleware/auth"); const router = (0, express_1.Router)(); router.get('/', auth_1.requireAuth, async (req, res) => { const locations = await prisma_1.default.location.findMany({ where: { companyId: req.user.companyId }, orderBy: { name: 'asc' }, }); return res.json(locations); }); router.post('/', auth_1.requireAuth, async (req, res) => { try { const loc = await prisma_1.default.location.create({ data: { ...req.body, companyId: req.user.companyId }, }); return res.status(201).json(loc); } catch (err) { return res.status(500).json({ error: 'Internal server error' }); } }); router.patch('/:id', auth_1.requireAuth, async (req, res) => { try { const loc = await prisma_1.default.location.update({ where: { id: req.params.id }, data: req.body }); return res.json(loc); } catch (err) { return res.status(500).json({ error: 'Internal server error' }); } }); router.delete('/:id', auth_1.requireAuth, async (req, res) => { try { await prisma_1.default.location.delete({ where: { id: req.params.id } }); return res.json({ message: 'Deleted' }); } catch (err) { return res.status(500).json({ error: 'Internal server error' }); } }); exports.default = router; //# sourceMappingURL=locations.js.map