- Introduced `PassengerInfo.tsx` for displaying trip details, including upcoming trips and fare information. - Added `PassengerSettings.tsx` for managing user-defined important places and fare settings. - Implemented validation functions for passenger settings in `passenger-settings.mjs`. - Created utility functions for transliterating stop names in `transliteration.ts`. - Developed weather hint functionality in `weather-hint.ts` to provide precipitation probabilities. - Established a mock server for testing passenger-related features in `passenger-server.mjs`. - Added comprehensive tests for passenger guide logic and transliteration functionality.
31 lines
2.1 KiB
JavaScript
31 lines
2.1 KiB
JavaScript
import { validDate } from './timetable.mjs';
|
|
|
|
const object = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
const text = (value, max) => typeof value === 'string' && value.trim().length > 0 && value.length <= max;
|
|
const id = (value, max = 1000000) => Number.isSafeInteger(value) && value > 0 && value <= max;
|
|
export function validPlaces(value) {
|
|
return Array.isArray(value) && value.length <= 3 && new Set(value.map(item => item?.stopId)).size === value.length
|
|
&& value.every(item => object(item) && Object.keys(item).every(key => ['stopId', 'name'].includes(key))
|
|
&& id(item.stopId) && text(item.name, 48));
|
|
}
|
|
export function validFareRules(value) {
|
|
return Array.isArray(value) && value.length <= 32 && new Set(value.map(item => item?.routeId)).size === value.length
|
|
&& value.every(item => object(item) && Object.keys(item).every(key => ['routeId', 'price', 'payment', 'checkedAt'].includes(key))
|
|
&& id(item.routeId, 999999999) && text(item.price, 40) && text(item.payment, 100) && validDate(item.checkedAt));
|
|
}
|
|
export function validFareByType(value) {
|
|
return Array.isArray(value) && value.length <= 2 && new Set(value.map(item => item?.type)).size === value.length
|
|
&& value.every(item => object(item) && Object.keys(item).every(key => ['cityId', 'type', 'price', 'payment', 'checkedAt'].includes(key))
|
|
&& id(item.cityId) && ['bus', 'minibus'].includes(item.type) && text(item.price, 40) && text(item.payment, 100) && validDate(item.checkedAt));
|
|
}
|
|
// Confirmed by the operator on 2026-10-11 for Polotsk, not a provider estimate.
|
|
// Keep that verification date fixed and bind the values to the actual city.
|
|
export const confirmedPolotskFares = [
|
|
{ cityId: 1, type: 'bus', price: '1,05 BYN', payment: 'QR-кодом или наличными', checkedAt: '2026-10-11' },
|
|
{ cityId: 1, type: 'minibus', price: '2,10 BYN', payment: 'QR-кодом или наличными', checkedAt: '2026-10-11' },
|
|
];
|
|
export const passengerDefaults = {
|
|
infoPlacesEnabled: true, infoFareEnabled: true, lastTripNoticeEnabled: true, weatherHintEnabled: true,
|
|
places: [], fareRules: [], fareByType: [],
|
|
};
|