mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
feat(trips): support custom tags and MCP tag management
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { tripTagNameSchema } from '../tag/trip-tag.schema';
|
||||
|
||||
/**
|
||||
* Trip API contract — single source of truth for the /api/trips aggregate-root
|
||||
@@ -42,6 +43,23 @@ export const TRIP_COSTS_MODES = ['split', 'totals'] as const;
|
||||
export const tripCostsModeSchema = z.enum(TRIP_COSTS_MODES);
|
||||
export type TripCostsMode = z.infer<typeof tripCostsModeSchema>;
|
||||
|
||||
export const MAX_TRIP_TAGS = 20;
|
||||
|
||||
export function tripTagKey(tag: string): string {
|
||||
return tag.trim().normalize('NFC').toLowerCase();
|
||||
}
|
||||
|
||||
export function uniqueTripTags(tags: readonly string[]): string[] {
|
||||
const byKey = new Map<string, string>();
|
||||
for (const tag of tags) {
|
||||
const key = tripTagKey(tag);
|
||||
if (key && !byKey.has(key)) byKey.set(key, tag.trim());
|
||||
}
|
||||
return [...byKey.values()];
|
||||
}
|
||||
|
||||
export const tripTagNamesSchema = z.array(tripTagNameSchema).max(MAX_TRIP_TAGS);
|
||||
|
||||
/**
|
||||
* Trip entity as returned by the trip list / get / create / update endpoints
|
||||
* (server/src/services/tripService.ts -> TRIP_SELECT). Columns of the `trips`
|
||||
@@ -53,6 +71,7 @@ export const tripSchema = z.object({
|
||||
user_id: z.number(),
|
||||
title: z.string(),
|
||||
description: z.string().nullable().optional(),
|
||||
tags: tripTagNamesSchema.optional(),
|
||||
start_date: z.string().nullable().optional(),
|
||||
end_date: z.string().nullable().optional(),
|
||||
currency: z.string(),
|
||||
@@ -105,6 +124,7 @@ export type TripRenameGuestRequest = z.infer<typeof tripRenameGuestRequestSchema
|
||||
export const tripCreateRequestSchema = z.object({
|
||||
title: z.string().min(1),
|
||||
description: z.string().nullable().optional(),
|
||||
tags: tripTagNamesSchema.optional(),
|
||||
start_date: z.string().nullable().optional(),
|
||||
end_date: z.string().nullable().optional(),
|
||||
currency: z.string().optional(),
|
||||
@@ -117,6 +137,7 @@ export type TripCreateRequest = z.infer<typeof tripCreateRequestSchema>;
|
||||
export const tripUpdateRequestSchema = z.object({
|
||||
title: z.string().optional(),
|
||||
description: z.string().nullable().optional(),
|
||||
tags: tripTagNamesSchema.optional(),
|
||||
start_date: z.string().nullable().optional(),
|
||||
end_date: z.string().nullable().optional(),
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user