mirror of
https://github.com/ArthurDanjou/artsite.git
synced 2026-01-21 08:23:21 +01:00
Implementing Drizzle to add views and like for post
This commit is contained in:
13
server/api/posts/like/[slug].put.ts
Normal file
13
server/api/posts/like/[slug].put.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useValidatedParams, z } from 'h3-zod'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { slug } = await useValidatedParams(event, {
|
||||
slug: z.string()
|
||||
})
|
||||
return useDB().update(tables.posts)
|
||||
.set({
|
||||
likes: sql`${tables.posts.likes}
|
||||
+ 1`
|
||||
})
|
||||
.where(eq(tables.posts.slug, slug))
|
||||
})
|
||||
Reference in New Issue
Block a user