update dev playground

This commit is contained in:
Robert Soriano
2022-05-19 10:26:13 -07:00
parent 87ed453425
commit f3e0165dd8
2 changed files with 39 additions and 7 deletions

View File

@@ -1,15 +1,17 @@
import * as trpc from '@trpc/server'
import { z } from 'zod'
export interface Todo {
userId: number
id: number
title: string
completed: boolean
}
const baseURL = 'https://jsonplaceholder.typicode.com'
const TodoShape = z.object({
userId: z.number(),
id: z.number(),
title: z.string(),
completed: z.boolean(),
})
export type Todo = z.infer<typeof TodoShape>
export const router = trpc.router()
.query('getTodos', {
async resolve() {
@@ -22,3 +24,12 @@ export const router = trpc.router()
return await $fetch<Todo>(`${baseURL}/todos/${req.input}`)
},
})
.mutation('addTodo', {
input: TodoShape,
async resolve(req) {
return await $fetch<Todo>(`${baseURL}/todos`, {
method: 'POST',
body: req.input,
})
},
})