릴리스: v1.4.19 템플릿 아이템 삭제 영향 경고 및 보존 정책 정리
This commit is contained in:
@@ -1413,35 +1413,35 @@ async function updateImageAssetLabel(assetId, label) {
|
||||
return mapImageAssetRow(rows[0])
|
||||
}
|
||||
|
||||
async function countTierListsUsingGameItem(itemId) {
|
||||
if (!itemId) return { totalCount: 0, publicCount: 0, privateCount: 0 }
|
||||
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT id, is_public, groups_json, pool_json
|
||||
FROM tierlists
|
||||
`
|
||||
)
|
||||
|
||||
let totalCount = 0
|
||||
let publicCount = 0
|
||||
let privateCount = 0
|
||||
|
||||
rows.forEach((row) => {
|
||||
const groups = parseJson(row.groups_json, [])
|
||||
const pool = parseJson(row.pool_json, [])
|
||||
const inGroups = groups.some((group) => (group?.itemIds || []).includes(itemId))
|
||||
const inPool = pool.some((item) => item?.id === itemId)
|
||||
if (!inGroups && !inPool) return
|
||||
totalCount += 1
|
||||
if (row.is_public) publicCount += 1
|
||||
else privateCount += 1
|
||||
})
|
||||
|
||||
return { totalCount, publicCount, privateCount }
|
||||
}
|
||||
|
||||
async function deleteGameItem(itemId) {
|
||||
const gameItemRows = await query('SELECT topic_id FROM topic_items WHERE id = ? LIMIT 1', [itemId])
|
||||
const gameId = gameItemRows[0]?.topic_id
|
||||
|
||||
if (gameId) {
|
||||
const tierListRows = await query(
|
||||
`
|
||||
SELECT id, author_id, topic_id, title, description, is_public, groups_json, pool_json, created_at, updated_at
|
||||
FROM tierlists
|
||||
WHERE topic_id = ?
|
||||
`,
|
||||
[gameId]
|
||||
)
|
||||
|
||||
for (const row of tierListRows) {
|
||||
const tierList = mapTierListRow(row)
|
||||
const nextGroups = (tierList.groups || []).map((group) => ({
|
||||
...group,
|
||||
itemIds: (group.itemIds || []).filter((id) => id !== itemId),
|
||||
}))
|
||||
const nextPool = (tierList.pool || []).filter((item) => item.id !== itemId)
|
||||
|
||||
await query(
|
||||
'UPDATE tierlists SET groups_json = ?, pool_json = ?, updated_at = ? WHERE id = ?',
|
||||
[serializeJson(nextGroups), serializeJson(nextPool), now(), tierList.id]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
await query('DELETE FROM topic_items WHERE id = ?', [itemId])
|
||||
}
|
||||
|
||||
@@ -2560,6 +2560,7 @@ module.exports = {
|
||||
createGameItem,
|
||||
updateGameItemLabel,
|
||||
updateGameItemDisplayOrder,
|
||||
countTierListsUsingGameItem,
|
||||
updateCustomItemLabel,
|
||||
updateImageAssetLabel,
|
||||
deleteGameItem,
|
||||
|
||||
Reference in New Issue
Block a user