fix(issues): guard missing companyId and enrich activity log context
Add 400 response for /issues without companyId, tag issue.updated activity with source:comment when triggered by a comment, and mark comment activities with updated:true when field changes accompany them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -184,6 +184,13 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Common malformed path when companyId is empty in "/api/companies/{companyId}/issues".
|
||||||
|
router.get("/issues", (_req, res) => {
|
||||||
|
res.status(400).json({
|
||||||
|
error: "Missing companyId in path. Use /api/companies/{companyId}/issues.",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/companies/:companyId/issues", async (req, res) => {
|
router.get("/companies/:companyId/issues", async (req, res) => {
|
||||||
const companyId = req.params.companyId as string;
|
const companyId = req.params.companyId as string;
|
||||||
assertCompanyAccess(req, companyId);
|
assertCompanyAccess(req, companyId);
|
||||||
@@ -522,6 +529,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const actor = getActorInfo(req);
|
const actor = getActorInfo(req);
|
||||||
|
const hasFieldChanges = Object.keys(previous).length > 0;
|
||||||
await logActivity(db, {
|
await logActivity(db, {
|
||||||
companyId: issue.companyId,
|
companyId: issue.companyId,
|
||||||
actorType: actor.actorType,
|
actorType: actor.actorType,
|
||||||
@@ -531,7 +539,12 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
|||||||
action: "issue.updated",
|
action: "issue.updated",
|
||||||
entityType: "issue",
|
entityType: "issue",
|
||||||
entityId: issue.id,
|
entityId: issue.id,
|
||||||
details: { ...updateFields, identifier: issue.identifier, _previous: Object.keys(previous).length > 0 ? previous : undefined },
|
details: {
|
||||||
|
...updateFields,
|
||||||
|
identifier: issue.identifier,
|
||||||
|
...(commentBody ? { source: "comment" } : {}),
|
||||||
|
_previous: hasFieldChanges ? previous : undefined,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let comment = null;
|
let comment = null;
|
||||||
@@ -555,6 +568,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
|||||||
bodySnippet: comment.body.slice(0, 120),
|
bodySnippet: comment.body.slice(0, 120),
|
||||||
identifier: issue.identifier,
|
identifier: issue.identifier,
|
||||||
issueTitle: issue.title,
|
issueTitle: issue.title,
|
||||||
|
...(hasFieldChanges ? { updated: true } : {}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user