refactor(core): update getAssetContext to throw error on missing asset

This commit is contained in:
yiling
2026-08-01 11:21:56 +08:00
parent 0324b95c7e
commit 6d80f06c22
4 changed files with 117 additions and 100 deletions
+21 -27
View File
@@ -36,15 +36,13 @@ const route = new Hono<{ Variables: { user: User } }>()
})
const parentCtx = await assetService.getAssetContext(req.parentId)
if (parentCtx?.teamId) {
await auditLogService.logAction({
action: AuditAction.asset_create,
teamId: parentCtx.teamId,
userId: user.id,
projectId: parentCtx.projectId,
itemId: newAsset.id,
})
}
await auditLogService.logAction({
action: AuditAction.asset_create,
teamId: parentCtx.teamId,
userId: user.id,
projectId: parentCtx.projectId,
itemId: newAsset.id,
})
return c.json(newAsset)
})
@@ -85,15 +83,13 @@ const route = new Hono<{ Variables: { user: User } }>()
})
const ctx = await assetService.getAssetContext(folderId)
if (ctx?.teamId) {
await auditLogService.logAction({
action: AuditAction.asset_update,
teamId: ctx.teamId,
userId: user.id,
projectId: ctx.projectId,
itemId: folderId,
})
}
await auditLogService.logAction({
action: AuditAction.asset_update,
teamId: ctx.teamId,
userId: user.id,
projectId: ctx.projectId,
itemId: folderId,
})
return c.json(updatedAsset)
})
@@ -152,15 +148,13 @@ const route = new Hono<{ Variables: { user: User } }>()
for (let i = 0; i < req.ids.length; i++) {
const ctx = contexts[i]
if (ctx?.teamId) {
await auditLogService.logAction({
action: AuditAction.asset_delete,
teamId: ctx.teamId,
userId: user.id,
projectId: ctx.projectId,
itemId: req.ids[i],
})
}
await auditLogService.logAction({
action: AuditAction.asset_delete,
teamId: ctx.teamId,
userId: user.id,
projectId: ctx.projectId,
itemId: req.ids[i],
})
}
return c.body(null, 204)