46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { z } from "zod";
|
||
import { HOUSEHOLD_ROLES, STORAGE_LOCATION_TYPES } from "@app/shared-types";
|
||
import { uuidSchema } from "./common.js";
|
||
|
||
export const createHouseholdInputSchema = z.object({
|
||
name: z.string().min(1).max(80).trim(),
|
||
weeklyBudgetMinor: z.number().int().min(0).max(10_000_000).optional(),
|
||
/** ISO 4217 – hushållets valuta (i18n-spec §20). Default SEK i databasen. */
|
||
currencyCode: z
|
||
.string()
|
||
.length(3)
|
||
.regex(/^[A-Za-z]{3}$/)
|
||
.transform((v) => v.toUpperCase())
|
||
.optional(),
|
||
});
|
||
export type CreateHouseholdInput = z.infer<typeof createHouseholdInputSchema>;
|
||
|
||
export const updateHouseholdInputSchema = createHouseholdInputSchema.partial();
|
||
export type UpdateHouseholdInput = z.infer<typeof updateHouseholdInputSchema>;
|
||
|
||
export const joinHouseholdInputSchema = z.object({
|
||
inviteCode: z.string().min(4).max(20).trim(),
|
||
});
|
||
export type JoinHouseholdInput = z.infer<typeof joinHouseholdInputSchema>;
|
||
|
||
export const updateMemberInputSchema = z.object({
|
||
role: z.enum(HOUSEHOLD_ROLES).optional(),
|
||
portionFactor: z.number().min(0.1).max(3).optional(),
|
||
});
|
||
export type UpdateMemberInput = z.infer<typeof updateMemberInputSchema>;
|
||
|
||
export const memberParamSchema = z.object({
|
||
id: uuidSchema,
|
||
userId: uuidSchema,
|
||
});
|
||
|
||
export const createStorageLocationInputSchema = z.object({
|
||
type: z.enum(STORAGE_LOCATION_TYPES),
|
||
name: z.string().min(1).max(60).trim(),
|
||
sublocations: z.array(z.string().min(1).max(60)).max(20).default([]),
|
||
});
|
||
export type CreateStorageLocationInput = z.infer<typeof createStorageLocationInputSchema>;
|
||
|
||
export const updateStorageLocationInputSchema = createStorageLocationInputSchema.partial();
|
||
export type UpdateStorageLocationInput = z.infer<typeof updateStorageLocationInputSchema>;
|