admin: streamline item modal actions
This commit is contained in:
@@ -394,6 +394,10 @@ router.get('/custom-items', requireAdmin, async (req, res) => {
|
||||
q: z.string().trim().max(120).optional().default(''),
|
||||
page: z.coerce.number().int().min(1).optional().default(1),
|
||||
limit: z.coerce.number().int().min(1).max(200).optional().default(50),
|
||||
collapseShared: z
|
||||
.union([z.string(), z.boolean(), z.number()])
|
||||
.optional()
|
||||
.transform((value) => value === true || value === 1 || value === '1' || value === 'true'),
|
||||
filter: z
|
||||
.enum(['library', 'all', 'user', 'template', 'asset', 'thumbnail', 'avatar', 'unused', 'unused-user', 'replaced-user', 'unused-admin'])
|
||||
.optional()
|
||||
@@ -407,6 +411,7 @@ router.get('/custom-items', requireAdmin, async (req, res) => {
|
||||
page: parsed.data.page,
|
||||
limit: parsed.data.limit,
|
||||
filterMode: parsed.data.filter,
|
||||
collapseShared: parsed.data.collapseShared,
|
||||
})
|
||||
res.json(result)
|
||||
})
|
||||
@@ -862,6 +867,27 @@ router.post('/custom-items/:itemId/promote', requireAdmin, async (req, res) => {
|
||||
res.json({ item })
|
||||
})
|
||||
|
||||
router.post('/custom-items/:itemId/unlink-template', requireAdmin, async (req, res) => {
|
||||
const schema = z.object({
|
||||
topicId: z.string().trim().min(1),
|
||||
})
|
||||
const parsed = schema.safeParse(req.body)
|
||||
if (!parsed.success) return res.status(400).json({ error: 'bad_request' })
|
||||
|
||||
const template = await findTopicById(parsed.data.topicId)
|
||||
if (!template) return res.status(404).json({ error: 'topic_not_found' })
|
||||
|
||||
const sourceItem = await findLibraryItemForReplacement(req.params.itemId)
|
||||
if (!sourceItem?.src) return res.status(404).json({ error: 'not_found' })
|
||||
|
||||
const templateItems = await listTopicItems(template.id)
|
||||
const matchedItems = templateItems.filter((item) => item?.src === sourceItem.src)
|
||||
if (!matchedItems.length) return res.status(404).json({ error: 'linked_template_item_not_found' })
|
||||
|
||||
await Promise.all(matchedItems.map((item) => deleteTopicItem(item.id)))
|
||||
res.json({ ok: true, deletedCount: matchedItems.length, topicId: template.id, src: sourceItem.src })
|
||||
})
|
||||
|
||||
router.post('/custom-items/:itemId/replace', requireAdmin, async (req, res) => {
|
||||
const schema = z.object({
|
||||
targetItemId: z.string().trim().min(1),
|
||||
|
||||
Reference in New Issue
Block a user