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: 2 additions & 0 deletions .workback/workback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Always use pnpm to install dependencies and run scripts
- Use the Node.js version defined in package.json file under "engines". Check the version with `node -v` and change it with `nvm use` if needed.
124 changes: 124 additions & 0 deletions packages/server/__tests__/unassignTask.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {getUserTeams, sendPublic, signUp} from './common'

test('Debug task unassignment notification issue', async () => {
// Sign up a user
const {userId, authToken} = await signUp()
console.log('[TEST] Signed up user:', userId)

// Get user's teams first
const teams = await getUserTeams(userId)
const teamId = teams[0].id
console.log('[TEST] Using team:', teamId)

// Create a task assigned to the user
const createTask = await sendPublic({
query: `
mutation CreateTask($newTask: CreateTaskInput!) {
createTask(newTask: $newTask) {
task {
id
userId
}
}
}
`,
variables: {
newTask: {
content:
'{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Debug task"}]}]}',
status: 'active',
teamId: teamId,
userId: userId
}
},
authToken
})

if (!createTask.data || !createTask.data.createTask) {
console.error('[TEST] Task creation failed:', JSON.stringify(createTask, null, 2))
throw new Error('Failed to create task')
}

const taskId = createTask.data.createTask.task.id
console.log(
'[TEST] Created task:',
taskId,
'assigned to:',
createTask.data.createTask.task.userId
)

// Try different GraphQL query formats to unassign the task
console.log('[TEST] Attempting task unassignment with format 1')
const updateTask1 = await sendPublic({
query: `
mutation UpdateTask($updatedTask: UpdateTaskInput!) {
updateTask(updatedTask: $updatedTask) {
taskId
}
}
`,
variables: {
updatedTask: {
id: taskId,
userId: null
}
},
authToken
})
console.log('[TEST] Update Task Result 1:', JSON.stringify(updateTask1, null, 2))

// Try a different format
console.log('[TEST] Attempting task unassignment with format 2')
const updateTask2 = await sendPublic({
query: `
mutation UpdateTask($id: ID!, $changes: TaskUpdateInput!) {
updateTask(id: $id, changes: $changes) {
taskId
}
}
`,
variables: {
id: taskId,
changes: {
userId: null
}
},
authToken
})
console.log('[TEST] Update Task Result 2:', JSON.stringify(updateTask2, null, 2))

// Try yet another format
console.log('[TEST] Attempting task unassignment with format 3')
const updateTask3 = await sendPublic({
query: `
mutation {
updateTask(updatedTask: {id: "${taskId}", userId: null}) {
taskId
}
}
`,
variables: {},
authToken
})
console.log('[TEST] Update Task Result 3:', JSON.stringify(updateTask3, null, 2))

// Check task status after all attempts
console.log('[TEST] Checking task status after update attempts')
const getTask = await sendPublic({
query: `
query GetTask($taskId: ID!) {
task(id: $taskId) {
id
userId
}
}
`,
variables: {
taskId: taskId
},
authToken
})
console.log('[TEST] Current task status:', JSON.stringify(getTask, null, 2))

// Don't make any assertions - this is purely for debugging
})
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ const publishChangeNotifications = async (
})
// add in the assignee changes
if (oldTask.userId && oldTask.userId !== task.userId) {
if (task.userId && task.userId !== changeUser.id && !usersToIgnore.includes(task.userId)) {
notificationsToAdd.push({
id: generateUID(),
type: 'TASK_INVOLVES' as const,
userId: task.userId,
involvement: 'ASSIGNEE' as const,
taskId: task.id,
changeAuthorId,
teamId: task.teamId
})
}
notificationsToAdd.push({
id: generateUID(),
type: 'TASK_INVOLVES' as const,
userId: task.userId,
involvement: 'ASSIGNEE' as const,
taskId: task.id,
changeAuthorId,
teamId: task.teamId
})

userIdsToRemove.push(oldTask.userId)
}

Expand Down
26 changes: 18 additions & 8 deletions packages/server/graphql/mutations/updateTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,26 @@ export default {
}
// RESOLUTION
const teamMembers = await dataLoader.get('teamMembersByTeamId').load(teamId)

// Construct updates object with explicit null handling
const updates: any = {
content: content ? validContent : undefined,
plaintextContent,
sortOrder: sortOrder || undefined,
status: status || undefined,
tags: content ? getTagsFromTipTapTask(validContent) : undefined
}

// Handle userId update explicitly
if (inputUserId === null) {
updates.userId = null
} else if (inputUserId !== undefined) {
updates.userId = inputUserId
}

const updateRes = await pg
.updateTable('Task')
.set({
content: content ? validContent : undefined,
plaintextContent,
sortOrder: sortOrder || undefined,
status: status || undefined,
userId: inputUserId || undefined,
tags: content ? getTagsFromTipTapTask(validContent) : undefined
})
.set(updates)
.where('id', '=', taskId)
.executeTakeFirst()
if (Number(updateRes.numChangedRows) === 0) {
Expand Down