mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
fix(roadtrip): keep the stay on each visit, not on the place (#3092)
A nullable day_assignments.stay_minutes holds the stay of one visit; a visit without one keeps reading the place's duration, so existing trips drive as before. REST PUT /trips/:tripId/assignments/:id/stay and the MCP tool set_assignment_stay write it with day_edit.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { User } from '../../types';
|
||||
import { CurrentUser } from '../auth-core/current-user.decorator';
|
||||
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
||||
import { ResponseContract } from '../common/response-contract';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import {
|
||||
AssignmentCreateDto,
|
||||
@@ -8,6 +9,7 @@ import {
|
||||
AssignmentMoveDto,
|
||||
AssignmentTimeDto,
|
||||
AssignmentEndDayDto,
|
||||
AssignmentStayDto,
|
||||
AssignmentNotesDto,
|
||||
AssignmentTransportDto,
|
||||
AssignmentRouteDto,
|
||||
@@ -15,6 +17,7 @@ import {
|
||||
} from './assignments.dto';
|
||||
import { AssignmentsService } from './assignments.service';
|
||||
import { Body, Controller, Delete, Get, Headers, HttpException, Param, Post, Put, UseGuards } from '@nestjs/common';
|
||||
import { assignmentResponseSchema } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* /api/trips/:tripId/days/:dayId/assignments — the day's ordered itinerary items.
|
||||
@@ -221,6 +224,25 @@ export class AssignmentOpsController {
|
||||
return { assignment };
|
||||
}
|
||||
|
||||
// #3092: the stay of one visit, so two visits of a place can last differently.
|
||||
// Same guard shape and 404 body as end-day; no reconcile, the stay touches
|
||||
// neither the day's order nor the journey skeleton.
|
||||
@RequirePermission('day_edit')
|
||||
@Put(':id/stay')
|
||||
@ResponseContract(assignmentResponseSchema)
|
||||
async stay(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() body: AssignmentStayDto,
|
||||
@Headers('x-socket-id') socketId?: string,
|
||||
) {
|
||||
const visit = await this.assignments.getAssignmentForTrip(id, tripId);
|
||||
if (!visit) throw new HttpException({ error: 'Assignment not found' }, 404);
|
||||
const assignment = await this.assignments.setStay(visit.id, body.stay_minutes);
|
||||
this.assignments.broadcast(tripId, 'assignment:updated', { assignment }, socketId);
|
||||
return { assignment };
|
||||
}
|
||||
|
||||
// #2163: the per-assignment note was write-once (create bodies, MCP, plugin
|
||||
// RPC) with no edit path anywhere. Same guard shape and 404 body as its
|
||||
// neighbours; no reconcile — the note doesn't touch the journey skeleton.
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
assignmentMoveRequestSchema,
|
||||
assignmentTimeRequestSchema,
|
||||
assignmentEndDayRequestSchema,
|
||||
assignmentStayRequestSchema,
|
||||
assignmentNotesRequestSchema,
|
||||
assignmentTransportRequestSchema,
|
||||
assignmentRouteRequestSchema,
|
||||
@@ -24,6 +25,7 @@ export class AssignmentReorderDto extends createZodDto(assignmentReorderRequestS
|
||||
export class AssignmentMoveDto extends createZodDto(assignmentMoveRequestSchema) {}
|
||||
export class AssignmentTimeDto extends createZodDto(assignmentTimeRequestSchema) {}
|
||||
export class AssignmentEndDayDto extends createZodDto(assignmentEndDayRequestSchema) {}
|
||||
export class AssignmentStayDto extends createZodDto(assignmentStayRequestSchema) {}
|
||||
export class AssignmentNotesDto extends createZodDto(assignmentNotesRequestSchema) {}
|
||||
export class AssignmentTransportDto extends createZodDto(assignmentTransportRequestSchema) {}
|
||||
export class AssignmentRouteDto extends createZodDto(assignmentRouteRequestSchema) {}
|
||||
|
||||
@@ -17,7 +17,9 @@ import {
|
||||
idSchema,
|
||||
assignmentCreateRequestSchema,
|
||||
assignmentEndDayRequestSchema,
|
||||
assignmentStayRequestSchema,
|
||||
type AssignmentEndDayRequest,
|
||||
type AssignmentStayRequest,
|
||||
} from '@trek/shared';
|
||||
|
||||
import { z } from 'zod';
|
||||
@@ -102,6 +104,31 @@ export class AssignmentsMcp {
|
||||
return ok({ assignment });
|
||||
}
|
||||
|
||||
@Tool({
|
||||
name: 'set_assignment_stay',
|
||||
description:
|
||||
'Set how long the road trip stands at this one visit, in minutes. Two visits of the same place keep their own stays: 0 drives past without stopping. Pass null to use the stay of the place (its duration_minutes) again.',
|
||||
inputSchema: {
|
||||
tripId: idSchema,
|
||||
assignmentId: idSchema,
|
||||
...assignmentStayRequestSchema.shape,
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'places', mode: 'write' },
|
||||
})
|
||||
async setAssignmentStay(
|
||||
{ tripId, assignmentId, stay_minutes }: AssignmentStayRequest & { tripId: number; assignmentId: number },
|
||||
ctx: McpContext,
|
||||
) {
|
||||
if (!(await this.assignments.verifyTripAccess(tripId, ctx.userId))) return noAccess();
|
||||
if (!(await this.guards.hasTripPermission('day_edit', tripId, ctx.userId))) return permissionDenied();
|
||||
if (!(await this.assignments.getAssignmentForTrip(assignmentId, tripId)))
|
||||
return errorResult('Assignment not found.');
|
||||
const assignment = await this.assignments.setStay(assignmentId, stay_minutes);
|
||||
this.guards.safeBroadcast(tripId, 'assignment:updated', { assignment });
|
||||
return ok({ assignment });
|
||||
}
|
||||
|
||||
@Tool({
|
||||
name: 'unassign_place',
|
||||
description: 'Remove a place assignment from a day.',
|
||||
|
||||
@@ -566,6 +566,18 @@ export class AssignmentsService {
|
||||
return await this.getAssignmentWithPlace(idNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* How long the drive stands at one visit (#3092). The stay used to be the place's
|
||||
* alone, so the same place planned twice on a day could not be stopped at once and
|
||||
* only driven past the other time. Null hands the visit back to the place's own
|
||||
* `duration_minutes`. No auto-sort and no journey reconcile: a stay moves neither
|
||||
* the day's order nor the skeleton mirror.
|
||||
*/
|
||||
async setStay(id: number, stayMinutes: number | null) {
|
||||
await this.dayAssignmentsRepo.setStayMinutes(id, stayMinutes);
|
||||
return await this.getAssignmentWithPlace(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the per-assignment note after creation (#2163) — until now the note
|
||||
* was write-once via the create paths (REST body, MCP tools, plugin RPC) and
|
||||
|
||||
@@ -38,6 +38,8 @@ export function formatAssignmentWithPlace(
|
||||
assignment_time: a.assignment_time ?? null,
|
||||
assignment_end_time: a.assignment_end_time ?? null,
|
||||
end_day: a.end_day === 1,
|
||||
// How long the drive stands at this visit (#3092); null reads the place's duration_minutes.
|
||||
stay_minutes: a.stay_minutes ?? null,
|
||||
leg_transport_mode: a.leg_transport_mode ?? null,
|
||||
incoming_leg_transport_mode: a.incoming_leg_transport_mode ?? null,
|
||||
// Kept on the day but not driven to (#2532).
|
||||
|
||||
@@ -198,6 +198,7 @@ export class DaysService {
|
||||
day_id: a.day_id,
|
||||
order_index: a.order_index,
|
||||
end_day: a.end_day === 1,
|
||||
stay_minutes: a.stay_minutes ?? null,
|
||||
route_excluded: a.route_excluded === 1,
|
||||
notes: a.notes,
|
||||
// Repeated here for the same reason stop_type is: the day list hides the stop
|
||||
|
||||
@@ -753,6 +753,7 @@ export class TripsService {
|
||||
reservation_status: a.reservation_status, reservation_notes: a.reservation_notes,
|
||||
reservation_datetime: a.reservation_datetime, assignment_time: a.assignment_time,
|
||||
assignment_end_time: a.assignment_end_time, end_day: a.end_day ?? 0, tour_stage_key: a.tour_stage_key,
|
||||
stay_minutes: a.stay_minutes ?? null,
|
||||
});
|
||||
assignmentMap.set(a.id, newAssignmentId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user