46 lines
859 B
TypeScript
46 lines
859 B
TypeScript
import { oc } from '@orpc/contract'
|
|
import {
|
|
createInsertSchema,
|
|
createSelectSchema,
|
|
createUpdateSchema,
|
|
} from 'drizzle-zod'
|
|
import { z } from 'zod'
|
|
import { todoTable } from '@/db/schema'
|
|
|
|
const selectSchema = createSelectSchema(todoTable)
|
|
|
|
const insertSchema = createInsertSchema(todoTable).omit({
|
|
id: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
})
|
|
|
|
const updateSchema = createUpdateSchema(todoTable).omit({
|
|
id: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
})
|
|
|
|
export const todoContract = {
|
|
list: oc.input(z.void()).output(z.array(selectSchema)),
|
|
|
|
create: oc.input(insertSchema).output(selectSchema),
|
|
|
|
update: oc
|
|
.input(
|
|
z.object({
|
|
id: z.uuid(),
|
|
data: updateSchema,
|
|
}),
|
|
)
|
|
.output(selectSchema),
|
|
|
|
remove: oc
|
|
.input(
|
|
z.object({
|
|
id: z.uuid(),
|
|
}),
|
|
)
|
|
.output(z.void()),
|
|
}
|