mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
feat(journey): keep the route recorded on a journey day from Dawarich, previewed first, with its gaps
A day header in the journey timeline now carries the Dawarich mark for an editor whose Dawarich answers (dimmed with the reason while offline). It opens a dialog that names the journey and the day and reads that one local day from the caller's own connection: a sketch of the route, distance, first and last time, pieces, gaps without recording, modes and whether tracks or thinned points answered. The day is cut in the zone Dawarich records in where its answer shows one, else in this device's, and a picker cuts it in any other. Nothing is kept before "Keep route". On a phone the same sheet opens from the journey's More options for the day of the card shown. What is kept is the preview that was seen: the save reads the day again and refuses with recording_changed when its hash moved, and the dialog shows the new version. The same day taken over twice keeps one version and announces nothing; a different version is replaced only on "Replace", never touching an entry or text. A failed read throws before any write, so the kept version stays. Gaps stay gaps: points are split where silence ends elsewhere, and no day is joined to the one before. The dialog says how many other people will see the route; editors may keep their own recording. Kept days show in the day header (distance, whose recording, since when, still running) and on the desktop and phone journey maps in the colour of their day's pins, winning over the live trail of their date, and stay drawn without Dawarich. A trip's GPX track is now drawn dashed as the plan, recorded routes solid. Shared links do not show recorded days. Remove route asks first and works without a connection. Server: migration 046160 adds journey_recorded_days (one row per journey, local day and source, segments as JSON, zone, window, fetch time, hash, importer kept past their account). The journey domain owns the rows through JourneyRecordedDaysService; the new journey-recordings domain takes a day over through DawarichTracksService.fetchDay, which reads past the cache, asks a window wide enough for every zone and refuses with DomainErrors. REST under /api/journeys/:id/recordings (list, preview, PUT and DELETE /:date) with @trek/shared contracts, and MCP list_journey_recorded_days, preview_journey_recorded_day, save_journey_recorded_day and delete_journey_recorded_day on the same service and access. A new user event journey:recording:updated keeps every open map current. JourneyTrack gains an optional kind. All 27 locales carry the strings; the Journey and Dawarich wiki pages and the MCP tool list say what it does.
This commit is contained in:
@@ -46,14 +46,15 @@ describe('ALL_ENTITIES', () => {
|
||||
* + tour_activity_exclusions, the tours a user left out of their own activity sums
|
||||
* + collection_tours, the whole tours a collection keeps
|
||||
* + tour_packing_links, the packing list or category a tour points at
|
||||
* + tour_source_hints, what the wanderer watch found about a snapshot's source)
|
||||
* + tour_source_hints, what the wanderer watch found about a snapshot's source
|
||||
* + journey_recorded_days, the recorded route a journey keeps per day)
|
||||
* is registered, and no two share a class name (a silent duplicate would
|
||||
* shadow one of them in `orm.getMetadata()`, exactly the kind of drift
|
||||
* `entity-schema-parity.test.ts` can't see — it iterates the metadata map,
|
||||
* which de-duplicates by class name).
|
||||
*/
|
||||
it('ENT-003: exactly 149 entities, every class name unique', () => {
|
||||
expect(ALL_ENTITIES.length).toBe(149);
|
||||
it('ENT-003: exactly 150 entities, every class name unique', () => {
|
||||
expect(ALL_ENTITIES.length).toBe(150);
|
||||
const names = ALL_ENTITIES.map((s) => s.meta.className);
|
||||
expect(new Set(names).size).toBe(names.length);
|
||||
});
|
||||
|
||||
@@ -43,7 +43,9 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
// + collection_tours: id, collection_id, name, waypoints, tour_type, origin, source_trip_title, source_tour_name
|
||||
// (a kept tour is only ever written whole, from the tour it was saved from).
|
||||
// + tour_source_hints: user_id (a hint is only ever written for the user whose snapshot it is about).
|
||||
const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 519;
|
||||
// + journey_recorded_days: id, journey_id, local_date, source_kind, utc_offset_minutes, window_from,
|
||||
// window_to, segments, point_count, content_hash, fetched_at (a kept day is only ever written whole).
|
||||
const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 530;
|
||||
|
||||
describe('entity class fields never carry a NaN initialiser (task-4-review-shape.md, Important 1)', () => {
|
||||
it('CLASSFIELD-001: new X() has no own property whose value is NaN, across all 133 entities', () => {
|
||||
|
||||
@@ -82,6 +82,7 @@ const UNNUMBERED = [
|
||||
'Migration20200101046130_snowshoeing_and_winter_hiking_are_ski_disciplines',
|
||||
'Migration20200101046140_tours_are_on_for_every_install',
|
||||
'Migration20200101046150_a_ski_tour_keeps_its_piste_router_options',
|
||||
'Migration20200101046160_a_journey_keeps_its_recorded_days',
|
||||
];
|
||||
// The last step the positional runner ever had; planLegacyBaseline refuses a
|
||||
// schema_version past it.
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* `JourneyRecordedDaysRepository` (JRN-01): a day a journey keeps written
|
||||
* whole, read back with the name of whose recording it is, one version per
|
||||
* journey, day and source with a second write replacing the first in place,
|
||||
* removed on its own, gone with its journey and kept past its importer.
|
||||
*/
|
||||
import { JourneyRecordedDays } from '../../../../src/db/entities/JourneyRecordedDays.entity';
|
||||
import { Journeys } from '../../../../src/db/entities/Journeys.entity';
|
||||
import { Users } from '../../../../src/db/entities/Users.entity';
|
||||
import type {
|
||||
JourneyRecordedDaysRepository,
|
||||
JourneyRecordedDayWrite,
|
||||
} from '../../../../src/db/repositories/JourneyRecordedDays.repository';
|
||||
import { dbNow } from '../../../../src/db/types';
|
||||
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
||||
import { makeJourney } from '../../../helpers/factories/journeys';
|
||||
import { countRows, deleteRows, updateRows } from '../../../helpers/factories/rows';
|
||||
import { makeUser } from '../../../helpers/factories/users';
|
||||
import { resetTestDb } from '../../../helpers/test-db';
|
||||
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
|
||||
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let days: JourneyRecordedDaysRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
days = t.repo(JourneyRecordedDays);
|
||||
});
|
||||
beforeEach(() => {
|
||||
resetTestDb(testDb);
|
||||
t.clear();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await t.close();
|
||||
testDb.close();
|
||||
});
|
||||
|
||||
async function journey() {
|
||||
const { user } = await makeUser(t, { username: 'marta' });
|
||||
const j = await makeJourney(t, user.id);
|
||||
return { user, journey: j };
|
||||
}
|
||||
|
||||
function day(journeyId: number, importedBy: number | null, overrides: Partial<JourneyRecordedDayWrite> = {}) {
|
||||
return {
|
||||
journey_id: journeyId,
|
||||
local_date: '2026-05-14',
|
||||
source: 'dawarich',
|
||||
source_kind: 'tracks',
|
||||
utc_offset_minutes: 120,
|
||||
window_from: '2026-05-13T22:00:00.000Z',
|
||||
window_to: '2026-05-14T22:00:00.000Z',
|
||||
segments: '[{"points":[[45.43,12.33],[45.44,12.34]],"mode":"walking"}]',
|
||||
point_count: 2,
|
||||
distance_m: 1300,
|
||||
content_hash: 'a'.repeat(64),
|
||||
truncated: 0,
|
||||
fetched_at: '2026-05-15T08:00:00.000Z',
|
||||
imported_by: importedBy,
|
||||
...overrides,
|
||||
} satisfies JourneyRecordedDayWrite;
|
||||
}
|
||||
|
||||
describe('JourneyRecordedDaysRepository', () => {
|
||||
it('JRDAYS-001: keeps a day whole and reads it back with the name of whose recording it is', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
const id = await days.upsertDay(day(j.id, user.id));
|
||||
|
||||
const row = await days.findDay(j.id, '2026-05-14', 'dawarich');
|
||||
expect(row).toMatchObject({
|
||||
id,
|
||||
journey_id: j.id,
|
||||
local_date: '2026-05-14',
|
||||
source_kind: 'tracks',
|
||||
utc_offset_minutes: 120,
|
||||
window_from: '2026-05-13T22:00:00.000Z',
|
||||
point_count: 2,
|
||||
distance_m: 1300,
|
||||
truncated: 0,
|
||||
imported_by: user.id,
|
||||
imported_by_username: 'marta',
|
||||
});
|
||||
expect(row?.created_at).toEqual(expect.any(String));
|
||||
expect(await days.findDay(j.id, '2026-05-15', 'dawarich')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('JRDAYS-002: a second write of the same day replaces the first in place, keeping its id', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
const first = await days.upsertDay(day(j.id, user.id));
|
||||
const second = await days.upsertDay(
|
||||
day(j.id, user.id, { content_hash: 'b'.repeat(64), point_count: 40, source_kind: 'points', distance_m: null }),
|
||||
);
|
||||
|
||||
expect(second).toBe(first);
|
||||
expect(await countRows(t, JourneyRecordedDays, {})).toBe(1);
|
||||
expect(await days.findDay(j.id, '2026-05-14', 'dawarich')).toMatchObject({
|
||||
content_hash: 'b'.repeat(64),
|
||||
point_count: 40,
|
||||
source_kind: 'points',
|
||||
distance_m: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('JRDAYS-003: lists the days of one journey earliest first, and only its own', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
const other = await makeJourney(t, user.id);
|
||||
await days.upsertDay(day(j.id, user.id, { local_date: '2026-05-16' }));
|
||||
await days.upsertDay(day(j.id, user.id, { local_date: '2026-05-14' }));
|
||||
await days.upsertDay(day(other.id, user.id, { local_date: '2026-05-15' }));
|
||||
|
||||
expect((await days.listForJourney(j.id)).map((row) => row.local_date)).toEqual(['2026-05-14', '2026-05-16']);
|
||||
expect(await days.listForJourney(9999)).toEqual([]);
|
||||
});
|
||||
|
||||
it('JRDAYS-004: removes one day and says whether there was one', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
await days.upsertDay(day(j.id, user.id));
|
||||
await days.upsertDay(day(j.id, user.id, { local_date: '2026-05-15' }));
|
||||
|
||||
expect(await days.deleteDay(j.id, '2026-05-14', 'dawarich')).toBe(true);
|
||||
expect(await days.deleteDay(j.id, '2026-05-14', 'dawarich')).toBe(false);
|
||||
expect((await days.listForJourney(j.id)).map((row) => row.local_date)).toEqual(['2026-05-15']);
|
||||
});
|
||||
|
||||
it('JRDAYS-005: a day goes with its journey and outlives the account that took it over', async () => {
|
||||
const { journey: j } = await journey();
|
||||
const { user: editor } = await makeUser(t);
|
||||
await days.upsertDay(day(j.id, editor.id));
|
||||
|
||||
await deleteRows(t, Users, { id: editor.id });
|
||||
expect(await days.findDay(j.id, '2026-05-14', 'dawarich')).toMatchObject({
|
||||
imported_by: null,
|
||||
imported_by_username: null,
|
||||
});
|
||||
|
||||
await deleteRows(t, Journeys, { id: j.id });
|
||||
expect(await countRows(t, JourneyRecordedDays, {})).toBe(0);
|
||||
});
|
||||
|
||||
it('JRDAYS-006: a replacing write stamps the time it was kept again', async () => {
|
||||
const { user, journey: j } = await journey();
|
||||
await days.upsertDay(day(j.id, user.id));
|
||||
const longAgo = dbNow(new Date('2020-01-01T00:00:00Z'));
|
||||
await updateRows(t, JourneyRecordedDays, { journey: j.id }, { created_at: longAgo, updated_at: longAgo });
|
||||
|
||||
await days.upsertDay(day(j.id, user.id, { content_hash: 'c'.repeat(64) }));
|
||||
|
||||
const row = await days.findDay(j.id, '2026-05-14', 'dawarich');
|
||||
expect(row?.created_at).toBe(longAgo);
|
||||
expect(row?.updated_at).not.toBe(longAgo);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user