Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.2.15",
"version": "1.2.16",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down
11 changes: 8 additions & 3 deletions src/resolvers/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ module.exports = {
* @param factories - factories for working with models
* @return {Promise<UserModel[]> | null}
*/
async visitedBy({ visitedBy, projectId }, _args, { factories, user }) {
async visitedBy({ visitedBy, projectId, workspaceId }, _args, { factories, user }) {
/**
* Crutch for Demo Workspace
* Prefer workspaceId from parent if present to avoid extra project lookup
*/
const project = await factories.projectsFactory.findById(projectId);
const resolvedWorkspaceId = workspaceId || (await (async () => {
const project = await factories.projectsFactory.findById(projectId);

return project ? project.workspaceId.toString() : undefined;
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check only verifies that project exists, but doesn't verify that project.workspaceId exists before calling toString(). If project.workspaceId is null or undefined, this will throw a TypeError.

Consider using optional chaining:

return project?.workspaceId?.toString();
Suggested change
return project ? project.workspaceId.toString() : undefined;
return project?.workspaceId?.toString();

Copilot uses AI. Check for mistakes.
})());

Comment on lines +49 to 54
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The immediately invoked async function expression (IIFE) is unnecessarily complex. Consider simplifying this to improve code readability:

let resolvedWorkspaceId = workspaceId;
if (!resolvedWorkspaceId) {
  const project = await factories.projectsFactory.findById(projectId);
  resolvedWorkspaceId = project?.workspaceId.toString();
}
Suggested change
const resolvedWorkspaceId = workspaceId || (await (async () => {
const project = await factories.projectsFactory.findById(projectId);
return project ? project.workspaceId.toString() : undefined;
})());
let resolvedWorkspaceId = workspaceId;
if (!resolvedWorkspaceId) {
const project = await factories.projectsFactory.findById(projectId);
resolvedWorkspaceId = project ? project.workspaceId.toString() : undefined;
}

Copilot uses AI. Check for mistakes.
if (project.workspaceId.toString() === '6213b6a01e6281087467cc7a') {
if (resolvedWorkspaceId === '6213b6a01e6281087467cc7a') {
return [ await factories.usersFactory.findById(user.id) ];
}

Expand Down
14 changes: 14 additions & 0 deletions src/resolvers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,20 @@ module.exports = {

const dailyEventsPortion = await factory.findDailyEventsPortion(limit, nextCursor, sort, filters, search);

/**
* Pass workspaceId down to events so nested resolvers (like Event.visitedBy)
* can avoid extra project lookups.
*/
if (dailyEventsPortion && Array.isArray(dailyEventsPortion.dailyEvents)) {
dailyEventsPortion.dailyEvents = dailyEventsPortion.dailyEvents.map((item) => ({
...item,
event: {
...item.event,
workspaceId: project.workspaceId && project.workspaceId.toString ? project.workspaceId.toString() : project.workspaceId,
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition project.workspaceId.toString checks for the existence of the toString method but doesn't check if project.workspaceId itself is null or undefined. This could throw a TypeError if project.workspaceId is null/undefined.

Consider changing to:

workspaceId: project.workspaceId?.toString() ?? project.workspaceId

or

workspaceId: project.workspaceId ? project.workspaceId.toString() : project.workspaceId
Suggested change
workspaceId: project.workspaceId && project.workspaceId.toString ? project.workspaceId.toString() : project.workspaceId,
workspaceId: project.workspaceId?.toString() ?? project.workspaceId,

Copilot uses AI. Check for mistakes.
},
}));
}

return dailyEventsPortion;
},

Expand Down