Track and save on groceries
1import z from "zod/v4";
2import { CreateStore, Store, Stores, StoresQuery } from "../schema/stores.js";
3import { base } from "./base.js";
4
5export const listStore = base
6 .route({
7 method: "GET",
8 path: "/stores",
9 })
10 .input(
11 z.object({
12 query: StoresQuery,
13 }),
14 )
15 .output(
16 z.object({
17 status: z.literal(200).describe("stores found"),
18 body: Stores,
19 }),
20 );
21
22export const getStore = base
23 .route({
24 method: "GET",
25 path: "/stores/:id",
26 })
27 .input(
28 z.object({
29 params: Store.pick({
30 id: true,
31 }),
32 }),
33 )
34 .output(
35 z.object({
36 status: z.literal(200).describe("store found"),
37 body: Store,
38 }),
39 )
40 .errors({
41 NOT_FOUND: {},
42 });
43
44export const createStore = base
45 .route({
46 method: "POST",
47 path: "/stores",
48 })
49 .input(
50 z.object({
51 body: CreateStore,
52 }),
53 )
54 .output(
55 z.object({
56 status: z.literal(201).describe("store created"),
57 body: Store,
58 }),
59 );
60
61export const deleteStore = base
62 .route({
63 method: "DELETE",
64 path: "/stores/:id",
65 })
66 .input(
67 z.object({
68 params: Store.pick({
69 id: true,
70 }),
71 }),
72 )
73 .output(
74 z.object({
75 status: z.literal(204).describe("store deleted"),
76 }),
77 );
78
79export const storeContract = {
80 list: listStore,
81 get: getStore,
82 create: createStore,
83 delete: deleteStore,
84};