fix(mcp): keep budget categories to the Costs keys, and say what a journal entry's visibility does

An assistant writing expenses through the MCP was told "e.g. Accommodation, Food,
Transport" and stored exactly that, so "Food" and "food" sat side by side in the
MCP totals while the Costs tab already read both as one. A typed category in any
case, or a common name like Hotel or Flight, is now stored as its fixed key on
every path (REST, MCP, linked booking costs), the totals the MCP reads group by
that key, and the tools name the real keys. The client reads categories through
the same shared mapping. Any other text is still kept as given.

The journal tools said that a private entry stays off the share link. It never
did: the share link shows every entry that is not a draft, whatever its
visibility, and the web editor has no visibility at all. The tools now say so
and point to is_draft, which is what keeps an entry to the contributors.

The wiki explains why the location button needs HTTPS and how to run TREK behind
an HTTPS tunnel while still using it over plain HTTP at home, and that Android's
photo picker drops a photo's location while Immich and Synology keep it.
This commit is contained in:
Maurice
2026-11-04 14:09:31 +01:00
parent 82295a1d3f
commit 50ea9a74c9
15 changed files with 153 additions and 49 deletions
+4 -4
View File
@@ -26,7 +26,7 @@ import { BudgetWritesService } from './budget-writes.service';
import { BudgetService } from './budget.service';
import { ExchangeRatesService } from './exchange-rates.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { idSchema, sumMinor, toMinor } from '@trek/shared';
import { COST_CATEGORY_HINT, idSchema, sumMinor, toMinor } from '@trek/shared';
import { z } from 'zod';
@@ -200,7 +200,7 @@ export class BudgetMcp {
inputSchema: {
tripId: idSchema,
name: z.string().min(1).max(200),
category: z.string().max(100).optional().describe('Budget category (e.g. Accommodation, Food, Transport)'),
category: z.string().max(100).optional().describe(COST_CATEGORY_HINT),
total_price: z.number().describe('Signed: a negative total records a refund/partial reimbursement (#2176)'),
currency: z
.string()
@@ -341,7 +341,7 @@ export class BudgetMcp {
tripId: idSchema,
itemId: idSchema,
name: z.string().min(1).max(200).optional(),
category: z.string().max(100).optional(),
category: z.string().max(100).optional().describe(COST_CATEGORY_HINT),
total_price: z.number().optional(),
currency: z
.string()
@@ -482,7 +482,7 @@ export class BudgetMcp {
inputSchema: {
tripId: idSchema,
name: z.string().min(1).max(200),
category: z.string().max(100).optional().describe('Budget category (e.g. Accommodation, Food, Transport)'),
category: z.string().max(100).optional().describe(COST_CATEGORY_HINT),
total_price: z.number().describe('Signed: a negative total records a refund/partial reimbursement (#2176)'),
note: z.string().max(500).optional(),
userIds: z
+7 -8
View File
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@mikro-orm/nestjs';
import type { BudgetFallbackFx, BudgetParticipantFinal, BudgetUnconverted, TrekWsPayload, TrekWsTripEventName } from '@trek/shared';
import { splitEqualShares, sumMinor, toMinor } from '@trek/shared';
import { costCategoryOf, splitEqualShares, storedCostCategory, sumMinor, toMinor } from '@trek/shared';
import { RealtimeService } from '../realtime/realtime.service';
import { PermissionsService } from '../permissions/permissions.service';
import { avatarUrl } from '../common/avatarUrl';
@@ -91,8 +91,7 @@ export function splitLegacyTicketNote(
* queries instead of a full listSettlements() scan, settlement usernames use
* COALESCE(display_name, username) like every item query, and updateMembers no
* longer double-applies avatarUrl.
*/
@Injectable()
*/@Injectable()
export class BudgetService {
constructor(
private readonly permissions: PermissionsService,
@@ -520,7 +519,7 @@ export class BudgetService {
const maxOrder = await this.budgetItemsRepo.maxSortOrder(tripId);
const sortOrder = (maxOrder !== null ? maxOrder : -1) + 1;
const cat = data.category || 'other';
const cat = storedCostCategory(data.category);
// Ensure category has a sort_order entry
const catExists = await this.budgetCategoryOrderRepo.exists(tripId, cat);
@@ -660,7 +659,7 @@ export class BudgetService {
// (the legacy `COALESCE(?, col)` truthy-wins shape), everything else
// passes `present = <field> !== undefined` (a true presence sentinel).
await this.budgetItemsRepo.update(id, {
category: [!!data.category, data.category || ''],
category: [!!data.category, data.category ? storedCostCategory(data.category) : ''],
name: [!!data.name, data.name || ''],
total_price: [data.total_price !== undefined, data.total_price !== undefined ? data.total_price : 0],
currency: [data.currency !== undefined, data.currency !== undefined ? (data.currency || null) : null],
@@ -705,11 +704,11 @@ export class BudgetService {
// If category changed, update category order table
if (data.category) {
const catExists = await this.budgetCategoryOrderRepo.exists(tripId, data.category);
const catExists = await this.budgetCategoryOrderRepo.exists(tripId, storedCostCategory(data.category));
if (!catExists) {
const maxCatOrder = await this.budgetCategoryOrderRepo.maxSortOrder(tripId);
const catOrder = (maxCatOrder !== null && maxCatOrder !== undefined ? maxCatOrder : -1) + 1;
await this.budgetCategoryOrderRepo.insertIgnore(tripId, data.category, catOrder);
await this.budgetCategoryOrderRepo.insertIgnore(tripId, storedCostCategory(data.category), catOrder);
}
}
@@ -1037,7 +1036,7 @@ export class BudgetService {
}
const cents = toMinor(convert(r.total_price || 0));
total += cents;
const cat = r.category || '';
const cat = costCategoryOf(r.category) ?? (r.category || '');
byCategory[cat] = (byCategory[cat] || 0) + cents;
}
return {
+1 -1
View File
@@ -383,7 +383,7 @@ export class JourneyMcp {
tags: z.array(z.string()).optional(),
pros_cons: PROS_CONS.optional().describe('The verdict on the place: what was worth it and what was not'),
visibility: ENTRY_VISIBILITY.optional().describe(
'Defaults to private; "shared" and "public" expose the entry through the journey share link',
'Stored with the entry, defaults to private. It does not decide the share link: every entry that is not a draft shows on the journey share link. Use is_draft to keep an entry to the contributors',
),
type: ENTRY_TYPE.optional().describe(
'Defaults to "entry"; "skeleton" is the stub TREK derives from a trip place and hides behind the hide-skeletons preference',