feat(assistant): collection list and saved place cards

This commit is contained in:
Maurice
2026-10-22 15:50:52 +02:00
parent 6e92c2777c
commit a440aefd43
68 changed files with 6052 additions and 92 deletions
@@ -1,5 +1,7 @@
import {
collectionDeleteManyRequestSchema,
collectionItemsRequestSchema,
collectionMembershipSchema,
collectionPlaceUpdateRequestSchema,
collectionReorderRequestSchema,
collectionSavePlaceRequestSchema,
@@ -63,3 +65,24 @@ describe('collectionReorderRequestSchema / collectionDeleteManyRequestSchema', (
expect(() => collectionDeleteManyRequestSchema.parse({ ids: ['a'] })).toThrow();
});
});
describe('collectionItemsRequestSchema', () => {
it('takes saved place and label ids, each optional, at most 50 places and 20 labels', () => {
expect(collectionItemsRequestSchema.parse({})).toEqual({});
const ids = (count: number) => Array.from({ length: count }, (_, i) => i + 1);
const asked = { placeIds: [1, 2], labelIds: [3] };
expect(collectionItemsRequestSchema.parse(asked)).toEqual(asked);
expect(() => collectionItemsRequestSchema.parse({ placeIds: ids(51) })).toThrow();
expect(() => collectionItemsRequestSchema.parse({ labelIds: ids(21) })).toThrow();
expect(() => collectionItemsRequestSchema.parse({ placeIds: [0] })).toThrow();
});
});
describe('collectionMembershipSchema', () => {
it("reads a list's colour where the server sends it, and a list without one from an older server", () => {
const list = { collection_id: 1, name: 'Paris', place_id: 2, status: 'want', can_edit: true };
const coloured = collectionMembershipSchema.parse({ saved: true, lists: [{ ...list, color: '#e11d48' }] });
expect(coloured.lists[0]?.color).toBe('#e11d48');
expect(collectionMembershipSchema.parse({ saved: true, lists: [list] }).lists[0]?.color).toBeUndefined();
});
});
@@ -1,3 +1,4 @@
import { idSchema } from '../common/primitives.schema';
import {
placeCategorySchema,
placeImageUrlSchema,
@@ -258,6 +259,21 @@ export const collectionCopyToTripRequestSchema = z.object({
});
export type CollectionCopyToTripRequest = z.infer<typeof collectionCopyToTripRequestSchema>;
/** What a copy into a trip did: how many went in, the ones the trip had, and each new trip place by its source. */
export const collectionCopyToTripResponseSchema = z.object({
copied: z.number(),
skipped: z.array(z.object({ id: z.number(), name: z.string() })),
created: z.array(z.object({ id: z.number(), source_id: z.number() })),
});
export type CollectionCopyToTripResponse = z.infer<typeof collectionCopyToTripResponseSchema>;
/** Saved places and labels asked for by their ids, across every list the caller can see (get_collection_items). */
export const collectionItemsRequestSchema = z.object({
placeIds: z.array(idSchema).max(50).optional(),
labelIds: z.array(idSchema).max(20).optional(),
});
export type CollectionItemsRequest = z.infer<typeof collectionItemsRequestSchema>;
// Fusion invitations. user_id is NUMERIC ONLY — the UI always sends an id from availableUsers.
export const collectionInviteRequestSchema = z.object({
collection_id: z.number(),
@@ -337,6 +353,28 @@ export const collectionDetailResponseSchema = z.object({
});
export type CollectionDetailResponse = z.infer<typeof collectionDetailResponseSchema>;
/**
* The asked-for places and labels with the lists they sit in: each list's
* size, colour, labels and people (names and roles, no addresses), and
* whether the caller may delete places from it (its owner or an admin). An id
* the caller cannot see is left out, never refused.
*/
const collectionItemsListSchema = collectionSchema
.pick({ id: true, name: true, color: true, place_count: true, is_owner: true, labels: true })
.extend({
can_delete: z.boolean(),
members: z.array(
collectionMemberSchema.pick({ user_id: true, username: true, status: true, role: true, is_owner: true }),
),
});
export const collectionItemsResponseSchema = z.object({
lists: z.array(collectionItemsListSchema),
places: z.array(collectionPlaceSchema),
labels: z.array(collectionLabelSchema),
});
export type CollectionItemsResponse = z.infer<typeof collectionItemsResponseSchema>;
/** Dedup outcome envelope reused by save + copy (matches placeService dedup UX). */
export const collectionSaveResultSchema = z.object({
place: collectionPlaceSchema.optional(),
@@ -352,6 +390,8 @@ export const collectionMembershipSchema = z.object({
z.object({
collection_id: z.number(),
name: z.string(),
/** The list's colour, for its dot; older servers leave it out. */
color: z.string().nullable().optional(),
place_id: z.number(),
/** Per-list status, so the picker can show and change it without a second round trip (#1469). */
status: collectionStatusSchema,