Searching.ton
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
601 B

2 years ago
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { z } from "zod"
const CreateSearchRequest = z.object({
text: z.string(),
})
export default resolver.pipe(
resolver.zod(CreateSearchRequest),
async ({ text }) => {
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
// const searchRequest = await db.searchRequest.create({ data: input });
const searchRequest = await db.searchRequest.upsert({
where: {
text,
},
update: { count: { increment: 1 } },
create: { text },
})
return searchRequest
}
)