Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(assistant): no awaits in loops and no value only used as a type in the journal code

Maurice13449c3338f9
diff --git a/server/src/nest/assistant/assistant-tools.service.ts b/server/src/nest/assistant/assistant-tools.service.ts
index 36cacee2d..0029d50aa 100644
--- a/server/src/nest/assistant/assistant-tools.service.ts
+++ b/server/src/nest/assistant/assistant-tools.service.ts
@@ -422,15 +422,13 @@ export class AssistantToolSession {
*/
private async outsideJourney(args: ToolArgs): Promise<string | null> {
if (this.pinArg !== JOURNEY_PINNED_ARG) return null;
- for (const key of JOURNEY_PART_ARGS) {
- if (args[key] === undefined) continue;
- const run = await this.callTool(JOURNEY_PART_READ, { entryId: args[key] });
+ const named = JOURNEY_PART_ARGS.filter((key) => args[key] !== undefined);
+ const runs = await Promise.all(named.map((key) => this.callTool(JOURNEY_PART_READ, { entryId: args[key] })));
+ const outside = runs.some((run) => {
const journey = (run.value as { journey?: { id?: unknown } } | null)?.journey;
- if (!run.ok || Number(journey?.id) !== this.pinnedId) {
- return 'This conversation is about one journey; that entry is not one of its entries.';
- }
- }
- return null;
+ return !run.ok || Number(journey?.id) !== this.pinnedId;
+ });
+ return outside ? 'This conversation is about one journey; that entry is not one of its entries.' : null;
}
}
diff --git a/server/src/nest/assistant/cards/journey/journey-header.ts b/server/src/nest/assistant/cards/journey/journey-header.ts
index c22428664..371618e30 100644
--- a/server/src/nest/assistant/cards/journey/journey-header.ts
+++ b/server/src/nest/assistant/cards/journey/journey-header.ts
@@ -30,16 +30,14 @@ export interface JournalHeaderLoaded {
}
/** The tools these cards are for. */
-const JOURNAL_HEADER_TOOLS = [
- 'create_journey',
- 'update_journey',
- 'delete_journey',
- 'add_journey_trip',
- 'remove_journey_trip',
- 'restore_journey_suggestions',
- 'update_journey_preferences',
-] as const;
-type HeaderTool = (typeof JOURNAL_HEADER_TOOLS)[number];
+type HeaderTool =
+ | 'create_journey'
+ | 'update_journey'
+ | 'delete_journey'
+ | 'add_journey_trip'
+ | 'remove_journey_trip'
+ | 'restore_journey_suggestions'
+ | 'update_journey_preferences';
/** The journal a call names, or none in a journey's own conversation, where the session pins it. */
export function journeyArgs(args: ToolArgs): ToolArgs {
diff --git a/server/src/nest/journey/journey-photo-links.service.ts b/server/src/nest/journey/journey-photo-links.service.ts
index 63d5262ae..e021fa574 100644
--- a/server/src/nest/journey/journey-photo-links.service.ts
+++ b/server/src/nest/journey/journey-photo-links.service.ts
@@ -64,12 +64,14 @@ export class JourneyPhotoLinksService {
const ids = [...new Set(req.photoIds)];
if (ids.some((id) => !onSource.has(id))) throw badRequest('Every photo must be one of this entry');
const kept = req.keep_in_source === true;
- await this.uow.transactional(async () => {
- for (const id of ids) {
+ // One after another: each link takes the next place among the target's photos.
+ await this.uow.transactional(() =>
+ ids.reduce<Promise<void>>(async (previous, id) => {
+ await previous;
if (!(await this.journeys.linkPhotoToEntry(req.toEntryId, id, userId))) throw notFound('Entry not found');
if (!kept) await this.journeys.unlinkPhotoFromEntry(fromEntryId, id, userId);
- }
- });
+ }, Promise.resolve()),
+ );
await this.announce([fromEntryId, req.toEntryId], sid);
return { moved: ids, fromEntryId, toEntryId: req.toEntryId, kept };
}
@@ -118,8 +120,10 @@ export class JourneyPhotoLinksService {
private async announce(entryIds: number[], sid?: string): Promise<void> {
const journeyId = await this.journeys.journeyIdOfEntry(entryIds[0]);
if (journeyId === null) return;
- for (const entryId of new Set(entryIds)) {
- await this.journeys.broadcastJourneyEvent(journeyId, 'journey:entry:updated', { entryId }, sid);
- }
+ await Promise.all(
+ [...new Set(entryIds)].map((entryId) =>
+ this.journeys.broadcastJourneyEvent(journeyId, 'journey:entry:updated', { entryId }, sid),
+ ),
+ );
}
}