feat: sledování objednávek přes Wolt
CI / Generate TypeScript types (push) Successful in 13s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m47s
CI / Build and push Docker image (push) Successful in 53s
CI / Notify (push) Successful in 2s

Vedle Bolt Food jde nově sledovat i objednávka z Woltu — stačí u objednané
skupiny vložit odkaz z track.wolt.com. Logika sledování je zobecněná do
registru rozvozových služeb (trackingProviders.ts): každá služba umí vytáhnout
kód ze sdílecího odkazu a dotázat se svého API, scheduler i stepper jsou společné.

- pole skupiny bolt* přejmenována na tracking* + nové trackingProvider
- endpoint /groups/setBoltTracking → /groups/setTracking
- Wolt: čas doručení z delivery_eta v časové zóně objednávky, 404 ukončí
  sledování, stav kurýra odvozen z is_delivering/is_delivering_other_order
- DEV simulace zůstává jen pro Bolt Food
This commit is contained in:
2026-08-24 11:27:56 +02:00
parent eeb1630391
commit 5c048fe1f1
25 changed files with 1326 additions and 869 deletions
+11 -10
View File
@@ -6,12 +6,12 @@ import { getWebsocket } from "../websocket";
import { getLogin } from "../auth";
import { parseToken } from "../utils";
import webpush from 'web-push';
import { ClientData, GroupState } from "../../../types/gen/types.gen";
import { ClientData, GroupState, TrackingProvider } from "../../../types/gen/types.gen";
import {
startBoltSimulation, advanceBoltSimulation, setBoltSimulationStep,
stopBoltSimulationByGroup, getBoltSimulation,
} from "../boltSimulator";
import { checkBoltTracking } from "../boltTracking";
import { checkOrderTracking } from "../orderTracking";
const router = express.Router();
const storage = getStorage();
@@ -201,7 +201,7 @@ router.post("/testPush", async (req, res, next) => {
} catch (e: any) { next(e) }
});
// --- DEV simulace sledování Bolt Food ---
// --- DEV simulace sledování Bolt Food (Wolt simulaci zatím nemá) ---
/** Nastaví/zruší sledovací token skupiny a zajistí stav ORDERED. Vrátí aktualizovaná data. */
async function applyBoltToken(groupId: string, token: string | undefined): Promise<ClientData> {
@@ -210,12 +210,13 @@ async function applyBoltToken(groupId: string, token: string | undefined): Promi
const d = current;
const group = d?.groups?.find(g => g.id === groupId);
if (!group) throw new Error('Skupina nebyla nalezena');
group.boltTrackingToken = token;
group.trackingProvider = token ? TrackingProvider.BOLT : undefined;
group.trackingCode = token;
if (token) {
group.state = GroupState.ORDERED;
} else {
group.boltOrderState = undefined;
group.boltCourierState = undefined;
group.trackingOrderState = undefined;
group.trackingCourierState = undefined;
}
return d!;
});
@@ -228,7 +229,7 @@ router.post("/bolt/simulate", async (req: Request<{}, any, any>, res, next) => {
if (!groupId) return res.status(400).json({ error: 'Chybí groupId' });
const token = startBoltSimulation(groupId);
await applyBoltToken(groupId, token);
await checkBoltTracking(); // okamžitý první poll → stav "accepted" + websocket
await checkOrderTracking(); // okamžitý první poll → stav "accepted" + websocket
res.status(200).json({ success: true, token, simulation: getBoltSimulation(groupId) });
} catch (e: any) { next(e); }
});
@@ -239,7 +240,7 @@ router.post("/bolt/advance", async (req: Request<{}, any, any>, res, next) => {
const groupId = req.body?.groupId;
if (!groupId) return res.status(400).json({ error: 'Chybí groupId' });
advanceBoltSimulation(groupId);
await checkBoltTracking();
await checkOrderTracking();
res.status(200).json({ success: true, simulation: getBoltSimulation(groupId) });
} catch (e: any) { next(e); }
});
@@ -250,7 +251,7 @@ router.post("/bolt/state", async (req: Request<{}, any, any>, res, next) => {
const { groupId, order_state, courier_state, etaSeconds } = req.body ?? {};
if (!groupId || !order_state) return res.status(400).json({ error: 'Chybí groupId nebo order_state' });
setBoltSimulationStep(groupId, { order_state, courier_state, etaSeconds });
await checkBoltTracking();
await checkOrderTracking();
res.status(200).json({ success: true, simulation: getBoltSimulation(groupId) });
} catch (e: any) { next(e); }
});
@@ -258,7 +259,7 @@ router.post("/bolt/state", async (req: Request<{}, any, any>, res, next) => {
/** Spustí jeden tik scheduleru okamžitě (bez čekání na interval). */
router.post("/bolt/poll", async (_req, res, next) => {
try {
await checkBoltTracking();
await checkOrderTracking();
res.status(200).json({ success: true });
} catch (e: any) { next(e); }
});