feat(mileage): add OneOS source priority controls
This commit is contained in:
@@ -3,6 +3,11 @@ import { getCache, queryDateMileage, queryRangeMileage, buildDateFilters } from
|
||||
import { filterByPermission, maskCustomerNames } from '../../auth/permissions.js';
|
||||
import type { AuthUser } from '../../auth/types.js';
|
||||
import type { CachedVehicle, MonitoringFilters, MonitoringResponse } from './types.js';
|
||||
import {
|
||||
DEFAULT_MILEAGE_SOURCE_PRIORITY,
|
||||
parseMileageSourcePriority,
|
||||
protocolsForSourcePriority,
|
||||
} from './source-policy.js';
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
@@ -14,6 +19,7 @@ const EMPTY_RESPONSE: MonitoringResponse = {
|
||||
page: 1,
|
||||
totalPages: 1,
|
||||
updatedAt: new Date().toISOString(),
|
||||
sourcePriority: [...DEFAULT_MILEAGE_SOURCE_PRIORITY],
|
||||
};
|
||||
|
||||
function applyFilters(vehicles: CachedVehicle[], params: {
|
||||
@@ -104,6 +110,8 @@ app.get('/', async (c) => {
|
||||
const page = Number(c.req.query('page')) || 1;
|
||||
const date = c.req.query('date') || '';
|
||||
const range = normalizeRange(c.req.query('startDate') || '', c.req.query('endDate') || '');
|
||||
const sourcePriority = parseMileageSourcePriority(c.req.query('sourcePriority'));
|
||||
const protocolPriority = protocolsForSourcePriority(sourcePriority);
|
||||
|
||||
const filterParams = {
|
||||
search: c.req.query('search') || '',
|
||||
@@ -128,7 +136,7 @@ app.get('/', async (c) => {
|
||||
|
||||
if (range) {
|
||||
try {
|
||||
const result = await queryRangeMileage(range.start, range.end);
|
||||
const result = await queryRangeMileage(range.start, range.end, protocolPriority);
|
||||
allVehicles = result.vehicles;
|
||||
rangeDailyTotals = result.dailyTotals;
|
||||
dateRange = { start: result.start, end: result.end };
|
||||
@@ -139,7 +147,7 @@ app.get('/', async (c) => {
|
||||
}
|
||||
} else if (date) {
|
||||
try {
|
||||
allVehicles = await queryDateMileage(date);
|
||||
allVehicles = await queryDateMileage(date, protocolPriority);
|
||||
filters = buildDateFilters(allVehicles);
|
||||
} catch (e: unknown) {
|
||||
console.error('monitoring date query error:', e);
|
||||
@@ -200,6 +208,7 @@ app.get('/', async (c) => {
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
updatedAt: dateRange?.end || date || getCache()?.updatedAt || new Date().toISOString(),
|
||||
sourcePriority,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user