Add database migration snapshots for comment_votes, comments, movies, and users tables

- Created 0009_snapshot.json with initial structure for comment_votes, comments, movies, and users tables.
- Created 0010_snapshot.json with updated structure for comments, including new fields: pinned and spoiler.
- Created 0011_snapshot.json with further updates to comments, adding anonymous field and refining existing structures.
This commit is contained in:
ngthanhvu
2026-07-24 00:06:03 -04:00
parent 70d8fc5bfa
commit 3d075f320c
22 changed files with 2832 additions and 74 deletions
+41
View File
@@ -0,0 +1,41 @@
import { eq } from 'drizzle-orm'
import { comments } from '../../database/schema'
import { getTokenFromEvent, verifyToken } from '../../utils/auth'
export default defineEventHandler(async (event) => {
const token = getTokenFromEvent(event)
if (!token) {
throw createError({ statusCode: 401, message: 'Chưa đăng nhập' })
}
const payload = verifyToken(token)
if (!payload) {
throw createError({ statusCode: 401, message: 'Phiên đăng nhập hết hạn' })
}
const id = Number(getRouterParam(event, 'id'))
if (!id) {
throw createError({ statusCode: 400, message: 'Thiếu ID bình luận' })
}
const db = useDb()
const [comment] = await db
.select()
.from(comments)
.where(eq(comments.id, id))
if (!comment) {
throw createError({ statusCode: 404, message: 'Không tìm thấy bình luận' })
}
if (comment.userId !== payload.id && payload.role !== 'admin') {
throw createError({ statusCode: 403, message: 'Không có quyền xóa bình luận này' })
}
await db
.delete(comments)
.where(eq(comments.id, id))
return { success: true }
})