mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix: five small defects the audit turned up in the release
An explicit null on a place's duration_minutes advertised a reset it never performed: the column sat behind COALESCE, so null and absent were the same thing and the day plan kept budgeting the old stay length. It clears now, and 0 still writes 0. update_trip_file and link_trip_file never learned the budget_item_id target the REST routes gained, so a receipt could not be attached to an expense from MCP. Added to both, along with the cross-trip check that goes with it: adding the field without it would have opened the hole the same change closed for REST. The roadtrip preferences PUT dropped the X-Socket-Id it was given, so the tab that saved a setting received its own change back and spent a second store commit and a route recompute on an answer it already had. Its two siblings on the same feature forward it. A shared journey did not carry the three "this journey does not use that field" switches, so the phone card read undefined, decided everything was switched on, and showed mood and weather chips on a journey whose owner had turned them off. An entry's country flag followed the pin when the entry was edited and not when the trip sync moved the place underneath it, so a stop dragged across a border kept the old flag with nothing to ever correct it. Also: dawarich.helpers.ts held a raw NUL byte as a hash separator, which made every search tool treat the file as binary and skip it. Same character, written as an escape.
This commit is contained in:
@@ -112,6 +112,7 @@ export class FilesMcp {
|
||||
description: fileUpdateRequestSchema.shape.description.describe('Free-text description, or an empty string to clear it'),
|
||||
place_id: fileUpdateRequestSchema.shape.place_id.describe('Place on the same trip to attach the file to, or null to detach it'),
|
||||
reservation_id: fileUpdateRequestSchema.shape.reservation_id.describe('Booking on the same trip to attach the file to, or null to detach it'),
|
||||
budget_item_id: fileUpdateRequestSchema.shape.budget_item_id.describe('Expense on the same trip to attach the file to (a receipt), or null to detach it'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'files', mode: 'write' },
|
||||
@@ -131,6 +132,7 @@ export class FilesMcp {
|
||||
const foreign = this.files.findForeignLinkTarget(tripId, {
|
||||
reservation_id: fields.reservation_id,
|
||||
place_id: fields.place_id,
|
||||
budget_item_id: fields.budget_item_id,
|
||||
});
|
||||
if (foreign) return errorResult(`Linked item does not belong to this trip (${foreign}).`);
|
||||
// The rest spread carries only the keys the caller actually sent, which is what
|
||||
@@ -150,6 +152,7 @@ export class FilesMcp {
|
||||
reservation_id: fileLinkRequestSchema.shape.reservation_id.describe('Booking on the same trip'),
|
||||
assignment_id: fileLinkRequestSchema.shape.assignment_id.describe('Day assignment (a place scheduled on a specific day) on the same trip'),
|
||||
place_id: fileLinkRequestSchema.shape.place_id.describe('Place on the same trip'),
|
||||
budget_item_id: fileLinkRequestSchema.shape.budget_item_id.describe('Expense on the same trip, for a receipt'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'files', mode: 'write' },
|
||||
@@ -165,8 +168,8 @@ export class FilesMcp {
|
||||
// The REST body allows all three to be absent and stores a link row pointing at
|
||||
// nothing. A tool caller that gets here with no target made a mistake, and saying
|
||||
// so is more useful than a success that attached the file to nothing.
|
||||
if (!targets.reservation_id && !targets.assignment_id && !targets.place_id) {
|
||||
return errorResult('Pass at least one of reservation_id, assignment_id or place_id.');
|
||||
if (!targets.reservation_id && !targets.assignment_id && !targets.place_id && !targets.budget_item_id) {
|
||||
return errorResult('Pass at least one of reservation_id, assignment_id, place_id or budget_item_id.');
|
||||
}
|
||||
const foreign = this.files.findForeignLinkTarget(tripId, targets);
|
||||
if (foreign) return errorResult(`Linked item does not belong to this trip (${foreign}).`);
|
||||
|
||||
Binary file not shown.
@@ -608,7 +608,7 @@ export class JourneyDomainService {
|
||||
// update everything on skeletons
|
||||
this.db.prepare(
|
||||
`
|
||||
UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, updated_at = ?
|
||||
UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
`,
|
||||
).run(
|
||||
@@ -618,6 +618,9 @@ export class JourneyDomainService {
|
||||
place.address || place.name,
|
||||
place.lat || null,
|
||||
place.lng || null,
|
||||
// The pin moved, so the flag has to follow it — the same rule updateEntry
|
||||
// states, and the one every sync write here used to skip.
|
||||
this.countryFor(place.lat ?? null, place.lng ?? null),
|
||||
now,
|
||||
entry.id,
|
||||
);
|
||||
@@ -625,10 +628,13 @@ export class JourneyDomainService {
|
||||
// for filled entries, only update location silently
|
||||
this.db.prepare(
|
||||
`
|
||||
UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, updated_at = ?
|
||||
UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
`,
|
||||
).run(place.address || place.name, place.lat || null, place.lng || null, now, entry.id);
|
||||
).run(
|
||||
place.address || place.name, place.lat || null, place.lng || null,
|
||||
this.countryFor(place.lat ?? null, place.lng ?? null), now, entry.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -815,8 +821,8 @@ export class JourneyDomainService {
|
||||
found.location_lng !== lng;
|
||||
if (stale) {
|
||||
this.db.prepare(
|
||||
`UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(place.name, entryDate, entryTime, locationName, lat, lng, now, found.id);
|
||||
`UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(place.name, entryDate, entryTime, locationName, lat, lng, this.countryFor(lat, lng), now, found.id);
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
@@ -825,8 +831,8 @@ export class JourneyDomainService {
|
||||
found.location_name !== locationName || found.location_lat !== lat || found.location_lng !== lng;
|
||||
if (stale) {
|
||||
this.db.prepare(
|
||||
`UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(locationName, lat, lng, now, found.id);
|
||||
`UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(locationName, lat, lng, this.countryFor(lat, lng), now, found.id);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,6 +256,13 @@ export class JourneyShareService {
|
||||
subtitle: journey.subtitle,
|
||||
cover_image: journey.cover_image,
|
||||
status: journey.status,
|
||||
// The three "this journey does not use that field" switches. A public
|
||||
// reader was getting mood and weather chips on a journey that had them
|
||||
// turned off, because the phone card reads these and they were not here
|
||||
// to read: undefined never equals 0, so both always looked switched on.
|
||||
show_verdict: journey.show_verdict ? 1 : 0,
|
||||
show_mood: journey.show_mood ? 1 : 0,
|
||||
show_weather: journey.show_weather ? 1 : 0,
|
||||
},
|
||||
entries: publicEntries,
|
||||
// A photo now carries the coordinates it was taken at, which is a location the
|
||||
|
||||
@@ -349,7 +349,7 @@ export class PlacesService {
|
||||
currency = COALESCE(?, currency),
|
||||
place_time = ?,
|
||||
end_time = ?,
|
||||
duration_minutes = COALESCE(?, duration_minutes),
|
||||
duration_minutes = ?,
|
||||
notes = ?,
|
||||
image_url = ?,
|
||||
google_place_id = ?,
|
||||
@@ -375,9 +375,11 @@ export class PlacesService {
|
||||
currency || null,
|
||||
place_time !== undefined ? place_time : existingPlace.place_time,
|
||||
end_time !== undefined ? end_time : existingPlace.end_time,
|
||||
// `?? null` rather than `|| null`: with COALESCE(?, duration_minutes) a
|
||||
// falsy-coerced 0 read as "absent" and silently kept the old duration.
|
||||
duration_minutes ?? null,
|
||||
// Not COALESCE, like its neighbours: the contract says an explicit null
|
||||
// clears the planned stay length, and COALESCE made null and absent the
|
||||
// same thing, so the field advertised a reset it never performed. 0 keeps
|
||||
// working, which a `|| null` bind would have swallowed.
|
||||
duration_minutes !== undefined ? duration_minutes : existingPlace.duration_minutes,
|
||||
notes !== undefined ? notes : existingPlace.notes,
|
||||
image_url !== undefined ? image_url : existingPlace.image_url,
|
||||
google_place_id !== undefined ? google_place_id : existingPlace.google_place_id,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import { RoadtripPreferencesService } from './roadtrip-preferences.service';
|
||||
import { Body, Controller, Get, Param, Put, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Headers, Param, Put, UseGuards } from '@nestjs/common';
|
||||
import { roadtripPreferencesUpdateSchema } from '@trek/shared';
|
||||
|
||||
import { createZodDto } from 'nestjs-zod';
|
||||
@@ -24,7 +24,7 @@ export class RoadtripPreferencesController {
|
||||
|
||||
@Put()
|
||||
@RequirePermission('day_edit')
|
||||
update(@Param('tripId') tripId: string, @Body() patch: PreferencesDto) {
|
||||
return { tripId: Number(tripId), preferences: this.preferences.update(Number(tripId), patch) };
|
||||
update(@Param('tripId') tripId: string, @Body() patch: PreferencesDto, @Headers('x-socket-id') socketId?: string) {
|
||||
return { tripId: Number(tripId), preferences: this.preferences.update(Number(tripId), patch, socketId) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export class RoadtripPreferencesService {
|
||||
return roadtripPreferencesSchema.parse(preferences);
|
||||
}
|
||||
|
||||
update(tripId: number, patch: RoadtripPreferences): RoadtripPreferences {
|
||||
update(tripId: number, patch: RoadtripPreferences, socketId?: string): RoadtripPreferences {
|
||||
const validated = roadtripPreferencesUpdateSchema.parse(patch);
|
||||
const saved = this.db.transaction(() => {
|
||||
const next = { ...this.read(tripId), ...validated };
|
||||
@@ -52,7 +52,11 @@ export class RoadtripPreferencesService {
|
||||
}
|
||||
return this.read(tripId);
|
||||
});
|
||||
this.realtime.broadcast(String(tripId), 'roadtripPreferences:changed', { preferences: saved });
|
||||
// The saving tab is left out, like every other trip mutation: it already has
|
||||
// the answer, and its own echo costs it a second store commit and the route
|
||||
// recompute that follows. The MCP tool passes none, which is right — nobody
|
||||
// there is holding the result already.
|
||||
this.realtime.broadcast(String(tripId), 'roadtripPreferences:changed', { preferences: saved }, socketId);
|
||||
return saved;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user