feat(api): add missing audit log calls to API endpoints

This commit is contained in:
yiling
2026-08-01 11:03:50 +08:00
parent 7dfb2c7f2f
commit 0324b95c7e
18 changed files with 695 additions and 2 deletions
+34
View File
@@ -299,6 +299,7 @@ const route = new Hono<{ Variables: { user: User } }>()
'/projects/:projectId/reparent',
zValidator('json', reparentAssetsRequestSchema),
async (c) => {
const projectId = c.req.param('projectId')
const user = c.get('user')
const req = c.req.valid('json')
@@ -325,10 +326,27 @@ const route = new Hono<{ Variables: { user: User } }>()
creatorId: user.id,
})
const proj = await prisma.project.findUnique({
where: { id: projectId },
select: { teamId: true },
})
if (proj) {
for (const assetId of req.assetIds) {
await auditLogService.logAction({
action: AuditAction.asset_reparent,
teamId: proj.teamId,
userId: user.id,
projectId,
itemId: assetId,
})
}
}
return c.body(null, 204)
},
)
.post('/projects/:projectId/copy', zValidator('json', copyAssetsRequestSchema), async (c) => {
const projectId = c.req.param('projectId')
const user = c.get('user')
const req = c.req.valid('json')
@@ -355,6 +373,22 @@ const route = new Hono<{ Variables: { user: User } }>()
creatorId: user.id,
})
const proj = await prisma.project.findUnique({
where: { id: projectId },
select: { teamId: true },
})
if (proj) {
for (const assetId of req.assetIds) {
await auditLogService.logAction({
action: AuditAction.asset_copy,
teamId: proj.teamId,
userId: user.id,
projectId,
itemId: assetId,
})
}
}
return c.body(null, 204)
})
.patch(