refactor: 重构Todo合约验证模式,分离插入与更新校验逻辑
- 重构Todo合约验证模式,分离插入和更新数据的校验Schema,并移除不必要的字段。
This commit is contained in:
@@ -7,11 +7,7 @@ import {
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { todoTable } from '@/db/schema'
|
import { todoTable } from '@/db/schema'
|
||||||
|
|
||||||
const selectSchema = createSelectSchema(todoTable).omit({
|
const selectSchema = createSelectSchema(todoTable)
|
||||||
id: true,
|
|
||||||
createdAt: true,
|
|
||||||
updatedAt: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
const insertSchema = createInsertSchema(todoTable).omit({
|
const insertSchema = createInsertSchema(todoTable).omit({
|
||||||
id: true,
|
id: true,
|
||||||
@@ -19,7 +15,11 @@ const insertSchema = createInsertSchema(todoTable).omit({
|
|||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateSchema = createUpdateSchema(todoTable)
|
const updateSchema = createUpdateSchema(todoTable).omit({
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
})
|
||||||
|
|
||||||
export const todoContract = {
|
export const todoContract = {
|
||||||
list: oc.input(z.void()).output(z.array(selectSchema)),
|
list: oc.input(z.void()).output(z.array(selectSchema)),
|
||||||
|
|||||||
Reference in New Issue
Block a user