refactor(todo): 移除 Todo API 示例
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import { createInsertSchema } from 'drizzle-zod'
|
||||
import { generatedFieldKeys } from '@/server/db/fields'
|
||||
import { todoTable } from '@/server/db/schema'
|
||||
|
||||
describe('todo insert schema', () => {
|
||||
const insertSchema = createInsertSchema(todoTable).omit(generatedFieldKeys)
|
||||
|
||||
test('accepts a minimal valid input', () => {
|
||||
expect(insertSchema.safeParse({ title: 'buy milk' }).success).toBe(true)
|
||||
})
|
||||
|
||||
test('rejects missing title', () => {
|
||||
expect(insertSchema.safeParse({}).success).toBe(false)
|
||||
})
|
||||
|
||||
test('rejects non-string title', () => {
|
||||
expect(insertSchema.safeParse({ title: 42 }).success).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -1,34 +0,0 @@
|
||||
import { oc } from '@orpc/contract'
|
||||
import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-zod'
|
||||
import { z } from 'zod'
|
||||
import { generatedFieldKeys } from '@/server/db/fields'
|
||||
import { todoTable } from '@/server/db/schema'
|
||||
|
||||
const selectSchema = createSelectSchema(todoTable)
|
||||
|
||||
const insertSchema = createInsertSchema(todoTable).omit(generatedFieldKeys)
|
||||
|
||||
const updateSchema = createUpdateSchema(todoTable)
|
||||
.omit(generatedFieldKeys)
|
||||
.refine((data) => Object.keys(data).length > 0, { message: 'At least one field is required' })
|
||||
|
||||
export const list = oc.input(z.void()).output(z.array(selectSchema))
|
||||
|
||||
export const create = oc.input(insertSchema).output(selectSchema)
|
||||
|
||||
export const update = oc
|
||||
.input(
|
||||
z.object({
|
||||
id: z.uuid(),
|
||||
data: updateSchema,
|
||||
}),
|
||||
)
|
||||
.output(selectSchema)
|
||||
|
||||
export const remove = oc
|
||||
.input(
|
||||
z.object({
|
||||
id: z.uuid(),
|
||||
}),
|
||||
)
|
||||
.output(z.void())
|
||||
Reference in New Issue
Block a user