mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
feat(server): validate collections reorder and delete-many bodies
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { collectionPlaceUpdateRequestSchema } from './collection.schema';
|
||||
import {
|
||||
collectionDeleteManyRequestSchema,
|
||||
collectionPlaceUpdateRequestSchema,
|
||||
collectionReorderRequestSchema,
|
||||
} from './collection.schema';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
@@ -20,3 +24,20 @@ describe('collectionPlaceUpdateRequestSchema', () => {
|
||||
expect(collectionPlaceUpdateRequestSchema.parse({ status: 'bogus' as never }).status).toBe('idea');
|
||||
});
|
||||
});
|
||||
|
||||
// The two ratchet schemas replace hand-rolled "array of numbers" checks — they
|
||||
// must stay exactly that permissive (empty arrays included, no int/positive).
|
||||
describe('collectionReorderRequestSchema / collectionDeleteManyRequestSchema', () => {
|
||||
it('accepts any array of numbers, empty included', () => {
|
||||
expect(collectionReorderRequestSchema.parse({ orderedIds: [] }).orderedIds).toEqual([]);
|
||||
expect(collectionReorderRequestSchema.parse({ orderedIds: [3, 1, 2] }).orderedIds).toEqual([3, 1, 2]);
|
||||
expect(collectionDeleteManyRequestSchema.parse({ ids: [] }).ids).toEqual([]);
|
||||
expect(collectionDeleteManyRequestSchema.parse({ ids: [7] }).ids).toEqual([7]);
|
||||
});
|
||||
|
||||
it('rejects non-arrays and non-numeric members', () => {
|
||||
expect(() => collectionReorderRequestSchema.parse({ orderedIds: 'nope' })).toThrow();
|
||||
expect(() => collectionReorderRequestSchema.parse({})).toThrow();
|
||||
expect(() => collectionDeleteManyRequestSchema.parse({ ids: ['a'] })).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,6 +128,14 @@ export const collectionUpdateRequestSchema = collectionCreateRequestSchema.parti
|
||||
});
|
||||
export type CollectionUpdateRequest = z.infer<typeof collectionUpdateRequestSchema>;
|
||||
|
||||
/** Reorder the caller's lists — every visible collection id in the desired order.
|
||||
* Plain z.number() (no .min/.int) mirrors the legacy hand-rolled check the DTO
|
||||
* ratchet replaced: any array of numbers, empty included. */
|
||||
export const collectionReorderRequestSchema = z.object({
|
||||
orderedIds: z.array(z.number()),
|
||||
});
|
||||
export type CollectionReorderRequest = z.infer<typeof collectionReorderRequestSchema>;
|
||||
|
||||
/** Save a place into a list from a raw maps/manual payload (or carrying provenance). */
|
||||
export const collectionSavePlaceRequestSchema = z.object({
|
||||
collection_id: z.number(),
|
||||
@@ -198,6 +206,13 @@ export type CollectionPlaceUpdateRequest = z.infer<typeof collectionPlaceUpdateR
|
||||
export const collectionSetStatusRequestSchema = z.object({ status: collectionStatusSchema });
|
||||
export type CollectionSetStatusRequest = z.infer<typeof collectionSetStatusRequestSchema>;
|
||||
|
||||
/** Bulk-delete saved places. Plain z.number() (no .min/.int) mirrors the legacy
|
||||
* hand-rolled check the DTO ratchet replaced (same shape as placeBulkDeleteRequestSchema). */
|
||||
export const collectionDeleteManyRequestSchema = z.object({
|
||||
ids: z.array(z.number()),
|
||||
});
|
||||
export type CollectionDeleteManyRequest = z.infer<typeof collectionDeleteManyRequestSchema>;
|
||||
|
||||
/** Copy one or many saved places INTO a trip (dedup precheck on server). */
|
||||
export const collectionCopyToTripRequestSchema = z.object({
|
||||
trip_id: z.number(),
|
||||
|
||||
Reference in New Issue
Block a user