Admin: gestión de sitios de voto (home_votesite)
- lib/admin-votes.ts: listVoteSites / createVoteSite / deleteVoteSite. - Routes /api/admin/votes (POST) y /api/admin/votes/[id] (DELETE), guard isAdmin. - Página /admin/votes (AdminVotesManager: crear/listar/borrar) + enlace en dashboard. - Conecta con la página de votación (/vote-points) ya existente. Verificado: guardas (307/403), CRUD del write layer OK (con env cargado). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { RowDataPacket, ResultSetHeader } from 'mysql2'
|
||||
import { db, DB } from './db'
|
||||
|
||||
export interface VoteSite {
|
||||
id: number
|
||||
name: string
|
||||
url: string
|
||||
image_url: string
|
||||
points: number
|
||||
}
|
||||
|
||||
export async function listVoteSites(): Promise<VoteSite[]> {
|
||||
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
||||
'SELECT id, name, url, image_url, points FROM home_votesite ORDER BY id',
|
||||
)
|
||||
return rows.map((r) => ({ id: r.id, name: r.name, url: r.url, image_url: r.image_url, points: r.points }))
|
||||
}
|
||||
|
||||
export async function createVoteSite(name: string, url: string, imageUrl: string, points: number): Promise<number> {
|
||||
const [res] = await db(DB.default).query<ResultSetHeader>(
|
||||
'INSERT INTO home_votesite (name, url, image_url, points, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())',
|
||||
[name, url, imageUrl, points],
|
||||
)
|
||||
return res.insertId
|
||||
}
|
||||
|
||||
export async function deleteVoteSite(id: number): Promise<void> {
|
||||
await db(DB.default).query('DELETE FROM home_votesite WHERE id = ?', [id])
|
||||
}
|
||||
Reference in New Issue
Block a user