릴리스: v0.1.43 토스트와 즐겨찾기 추가
This commit is contained in:
@@ -176,6 +176,7 @@ router.get('/tierlists', requireAdmin, async (req, res) => {
|
||||
queryText: parsed.data.q,
|
||||
page: parsed.data.page,
|
||||
limit: parsed.data.limit,
|
||||
currentUserId: req.session?.userId || '',
|
||||
})
|
||||
res.json(result)
|
||||
})
|
||||
@@ -332,6 +333,7 @@ router.post('/tierlists/:tierListId/create-game-template', requireAdmin, async (
|
||||
const schema = z.object({
|
||||
gameId: z.string().trim().min(1).max(120),
|
||||
name: z.string().trim().min(1).max(120),
|
||||
itemIds: z.array(z.string().min(1)).optional().default([]),
|
||||
})
|
||||
const parsed = schema.safeParse(req.body)
|
||||
if (!parsed.success) return res.status(400).json({ error: 'bad_request' })
|
||||
@@ -343,7 +345,10 @@ router.post('/tierlists/:tierListId/create-game-template', requireAdmin, async (
|
||||
if (!tierList) return res.status(404).json({ error: 'not_found' })
|
||||
|
||||
const result = await createGameTemplateFromTierList({
|
||||
tierList,
|
||||
tierList: {
|
||||
...tierList,
|
||||
pool: parsed.data.itemIds.length ? (tierList.pool || []).filter((item) => parsed.data.itemIds.includes(item.id)) : tierList.pool,
|
||||
},
|
||||
gameId: parsed.data.gameId,
|
||||
gameName: parsed.data.name,
|
||||
})
|
||||
|
||||
@@ -11,6 +11,8 @@ const {
|
||||
saveTierList,
|
||||
createCustomItem,
|
||||
findUserById,
|
||||
favoriteTierList,
|
||||
unfavoriteTierList,
|
||||
} = require('../db')
|
||||
const { requireAuth } = require('../middleware/auth')
|
||||
|
||||
@@ -87,7 +89,7 @@ const tierListUpsertSchema = z.object({
|
||||
|
||||
router.get('/public', async (req, res) => {
|
||||
const gameId = req.query.gameId
|
||||
const lists = await listPublicTierLists(gameId)
|
||||
const lists = await listPublicTierLists(gameId, req.session?.userId || '')
|
||||
res.json({ tierLists: lists })
|
||||
})
|
||||
|
||||
@@ -97,7 +99,7 @@ router.get('/me', requireAuth, async (req, res) => {
|
||||
})
|
||||
|
||||
router.get('/:id', async (req, res) => {
|
||||
const t = await findTierListById(req.params.id)
|
||||
const t = await findTierListById(req.params.id, req.session?.userId || '')
|
||||
if (!t) return res.status(404).json({ error: 'not_found' })
|
||||
if (!t.isPublic) {
|
||||
if (!req.session?.userId) return res.status(403).json({ error: 'forbidden' })
|
||||
@@ -108,7 +110,7 @@ router.get('/:id', async (req, res) => {
|
||||
})
|
||||
|
||||
router.delete('/:id', requireAuth, async (req, res) => {
|
||||
const tierList = await findTierListById(req.params.id)
|
||||
const tierList = await findTierListById(req.params.id, req.session.userId)
|
||||
if (!tierList) return res.status(404).json({ error: 'not_found' })
|
||||
if (tierList.authorId !== req.session.userId) return res.status(403).json({ error: 'forbidden' })
|
||||
|
||||
@@ -116,6 +118,25 @@ router.delete('/:id', requireAuth, async (req, res) => {
|
||||
res.json({ ok: true })
|
||||
})
|
||||
|
||||
router.post('/:id/favorite', requireAuth, async (req, res) => {
|
||||
const tierList = await findTierListById(req.params.id, req.session.userId)
|
||||
if (!tierList) return res.status(404).json({ error: 'not_found' })
|
||||
if (!tierList.isPublic && tierList.authorId !== req.session.userId) return res.status(403).json({ error: 'forbidden' })
|
||||
|
||||
await favoriteTierList({ userId: req.session.userId, tierListId: tierList.id })
|
||||
const updated = await findTierListById(tierList.id, req.session.userId)
|
||||
res.json({ tierList: normalizeTierList(updated) })
|
||||
})
|
||||
|
||||
router.delete('/:id/favorite', requireAuth, async (req, res) => {
|
||||
const tierList = await findTierListById(req.params.id, req.session.userId)
|
||||
if (!tierList) return res.status(404).json({ error: 'not_found' })
|
||||
|
||||
await unfavoriteTierList({ userId: req.session.userId, tierListId: tierList.id })
|
||||
const updated = await findTierListById(tierList.id, req.session.userId)
|
||||
res.json({ tierList: normalizeTierList(updated) })
|
||||
})
|
||||
|
||||
router.post('/custom-items', requireAuth, upload.single('image'), async (req, res) => {
|
||||
if (!req.file) return res.status(400).json({ error: 'file_required' })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user