All files / src/features/usage-charges schemas.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

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                  1x   1x     1x         1x           1x  
// Input for usage charges, shared by the forms and the server functions.
// Errors are reason codes (src/lib/reasons.ts), never text.
import { z } from 'zod'
import {
  monthStartDate,
  typedAmount,
} from '#/features/recurring-amounts/schemas'
import { chargeFields } from '#/lib/charge-fields'
 
const id = z.string().min(1).max(64)
 
export const propertyRefInput = z.object({ propertyId: id })
 
/** A new usage charge with its first amount ("Adding a usage charge"). */
export const addUsageChargeInput = propertyRefInput
  .and(chargeFields)
  .and(z.object({ amount: typedAmount, from: monthStartDate }))
 
/** A usage charge's new amount from a date ("Changing a usage charge"). */
export const setUsageChargeInput = propertyRefInput.extend({
  chargeId: id,
  amount: typedAmount,
  from: monthStartDate,
})
 
export const usageChargeRefInput = propertyRefInput.extend({ chargeId: id })