- Server: Express.js with 13 API route files (auth, regulations, contacts, calendar, truck stops, bridges, weigh stations, alerts, load board, escort locator, orders, documents, contributions) - Database: PostgreSQL with Prisma ORM, 15 models covering all modules - Auth: JWT + bcrypt with role-based access control (driver/carrier/escort/admin) - Geospatial: Haversine distance filtering on truck stops, bridges, escorts - Seed script: Imports all existing mock data (51 states, contacts, equipment, truck stops, bridges, weigh stations, alerts, seasonal restrictions) - Frontend: All 10 data-driven pages now fetch from /api instead of mock-data.js - API client (api.js): Compatibility layer that transforms API responses to match existing frontend rendering code, minimizing page-level changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
35 lines
935 B
JavaScript
35 lines
935 B
JavaScript
const express = require('express');
|
|
const prisma = require('../config/db');
|
|
|
|
const router = express.Router();
|
|
|
|
// GET /api/contacts — all state contacts
|
|
router.get('/', async (req, res, next) => {
|
|
try {
|
|
const contacts = await prisma.contact.findMany({
|
|
include: { state: { select: { name: true, abbr: true } } },
|
|
orderBy: { state: { name: 'asc' } },
|
|
});
|
|
res.json(contacts);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
});
|
|
|
|
// GET /api/contacts/:stateAbbr
|
|
router.get('/:stateAbbr', async (req, res, next) => {
|
|
try {
|
|
const abbr = req.params.stateAbbr.toUpperCase();
|
|
const state = await prisma.state.findUnique({
|
|
where: { abbr },
|
|
include: { contact: true },
|
|
});
|
|
if (!state) return res.status(404).json({ error: `State '${abbr}' not found.` });
|
|
res.json(state.contact || { error: 'No contact data for this state.' });
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|