feat: add pinned presets with admin pin/unpin and dedicated section

This commit is contained in:
2026-04-28 23:32:32 +08:00
parent 23fa7be89f
commit cc34fd17ef
8 changed files with 1970 additions and 20 deletions
+36
View File
@@ -138,6 +138,42 @@ export const performanceVerifyRoutes = new Elysia({
params: t.Object({ id: t.String() }),
},
)
// ── Pin a preset (admin only) ──────────────────────────────────────
.post(
"/:id/pin",
async ({ request, params, set }) => {
const guard = await requireRole(request.headers, ["admin"])
if (!guard.ok) { set.status = guard.status; return { error: guard.error } }
const [entry] = await db
.update(performanceEntries)
.set({ isPinned: true, pinnedAt: new Date() })
.where(eq(performanceEntries.id, params.id))
.returning()
if (!entry) { set.status = 404; return { error: "Entry not found" } }
return { entry }
},
{ params: t.Object({ id: t.String() }) },
)
// ── Unpin a preset (admin only) ────────────────────────────────────
.delete(
"/:id/pin",
async ({ request, params, set }) => {
const guard = await requireRole(request.headers, ["admin"])
if (!guard.ok) { set.status = guard.status; return { error: guard.error } }
const [entry] = await db
.update(performanceEntries)
.set({ isPinned: false, pinnedAt: null })
.where(eq(performanceEntries.id, params.id))
.returning()
if (!entry) { set.status = 404; return { error: "Entry not found" } }
return { entry }
},
{ params: t.Object({ id: t.String() }) },
)
// ── User-scoped soft delete (owner or admin) ────────────────────
.delete(
"/:id/user-delete",
+2
View File
@@ -87,6 +87,8 @@ export const performanceEntries = pgTable(
// Moderation
isRemoved: boolean("is_removed").default(false).notNull(),
isPinned: boolean("is_pinned").default(false).notNull(),
pinnedAt: timestamp("pinned_at"),
removedReason: text("removed_reason"),
// Community rating