All files / src/features/year-summary schemas.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41            2x               2x     3x         2x           2x   2x         2x          
// Input for the year summary's server functions and routes (openspec:
// year-summary). The year is optional: without it the summary opens on the
// opening year.
import { z } from 'zod'
 
/** A year the summary may be asked for; the range is clamped later. */
export const summaryYear = z.number().int().min(2000).max(2100)
 
/**
 * A year as the pages' URL gives it: one outside 2000–2100 is moved to the
 * nearest end, and one that isn't a whole number is left out, so the server
 * opens the nearest year it has (openspec: year-summary, "The year the
 * summary opens on").
 */
export const urlYear = z
  .number()
  .int()
  .transform((year) => Math.min(Math.max(year, 2000), 2100))
  .optional()
  .catch(undefined)
 
/** Whose figures: another owner's user id, or `whole` for the whole flats. */
export const personChoice = z.union([
  z.literal('whole'),
  z.string().min(1).max(64),
])
 
/** A person as the pages' URL gives it: anything else is left out. */
export const urlPerson = personChoice.optional().catch(undefined)
 
export const yearSummaryInput = z.object({
  year: summaryYear.optional(),
  person: personChoice.optional(),
})
 
export const flatYearInput = z.object({
  propertyId: z.string().min(1).max(64),
  year: summaryYear.optional(),
  person: personChoice.optional(),
})