63 lines
3.4 KiB
JavaScript
63 lines
3.4 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Public Data Export API routes — mounted at /api/v1/
|
|
* All routes authenticated via checkApiKey (X-API-Key header).
|
|
*
|
|
* ─── Integration guide ───────────────────────────────────────────────────────
|
|
*
|
|
* Session summary:
|
|
* GET /api/v1/jobs/:jobId/sessions
|
|
* → Returns one record per uploaded file for the job.
|
|
* reportConfirmed: false when applicator has not yet confirmed values in Report Settings.
|
|
* Re-fetch when your data warehouse detects this field changed.
|
|
*
|
|
* Raw GPS trace (paginated):
|
|
* GET /api/v1/jobs/:jobId/sessions/:fileId/records
|
|
* Query: startingAfter=<cursor>, limit=<n≤2000>, interval=<seconds>
|
|
* → Use interval=1 or interval=5 for lighter Power BI queries.
|
|
* → Use the /export endpoint instead for full bulk loads.
|
|
*
|
|
* Spray-area polygons:
|
|
* GET /api/v1/jobs/:jobId/areas
|
|
* → GeoJSON FeatureCollection of planned spray-area polygons.
|
|
*
|
|
* Async bulk export:
|
|
* POST /api/v1/jobs/:jobId/export body: { format: 'csv'|'geojson', interval?: number }
|
|
* GET /api/v1/exports/:exportId poll for { status, downloadUrl }
|
|
* GET /api/v1/exports/:exportId/download stream file
|
|
*
|
|
* ─────────────────────────────────────────────────────────────────────────────
|
|
*
|
|
* FE integration notes:
|
|
* - The key management UI (create/list/revoke keys) lives at /api/keys — see routes/api_keys.js.
|
|
* - The API key is supplied as the X-API-Key request header, NOT Authorization Bearer.
|
|
* - For Power BI: use paginated records endpoint with startingAfter cursor for incremental refresh.
|
|
* - For ArcGIS / daily batch: use the export endpoint — POST once, poll, then download CSV/GeoJSON.
|
|
*/
|
|
module.exports = function (app) {
|
|
const router = require('express').Router();
|
|
const { checkApiKey } = require('../middlewares/app_validator');
|
|
const pubCtl = require('../controllers/api_pub');
|
|
const exportCtl = require('../controllers/api_export');
|
|
|
|
// Apply API key auth to all /api/v1/ routes
|
|
router.use(checkApiKey);
|
|
|
|
// ── Session summary ──────────────────────────────────────────────────────
|
|
router.get('/jobs/:jobId/sessions', pubCtl.getSessions);
|
|
|
|
// ── Raw GPS trace records ────────────────────────────────────────────────
|
|
router.get('/jobs/:jobId/sessions/:fileId/records', pubCtl.getSessionRecords);
|
|
|
|
// ── Spray-area GeoJSON polygons ──────────────────────────────────────────
|
|
router.get('/jobs/:jobId/areas', pubCtl.getAreas);
|
|
|
|
// ── Async export ─────────────────────────────────────────────────────────
|
|
router.post('/jobs/:jobId/export', exportCtl.triggerExport);
|
|
router.get('/exports/:exportId', exportCtl.getExportStatus);
|
|
router.get('/exports/:exportId/download', exportCtl.downloadExport);
|
|
|
|
app.use('/api/v1', router);
|
|
};
|