{"record":{"id":"38f4ded8deee3476","repo":"gitroomhq/postiz-app","slug":"user-is-not-part-of-this-organization","errorCode":null,"errorMessage":"User is not part of this organization","messagePattern":"User is not part of this organization","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts","lineNumber":165,"sourceCode":"      org.id,\n      body.role as 'USER' | 'ADMIN'\n    );\n\n    if (!added) {\n      throw new HttpException(\n        'Could not add the user to the organization',\n        400\n      );\n    }\n\n    return { added: true };\n  }\n\n  async deleteTeamMember(org: Organization, userId: string) {\n    const userOrgs = await this._organizationRepository.getOrgsByUserId(userId);\n    const findOrgToDelete = userOrgs.find((orgUser) => orgUser.id === org.id);\n    if (!findOrgToDelete) {\n      throw new Error('User is not part of this organization');\n    }\n\n    // @ts-ignore\n    const myRole = org.users[0].role;\n    const userRole = findOrgToDelete.users[0].role;\n    const myLevel = myRole === 'USER' ? 0 : myRole === 'ADMIN' ? 1 : 2;\n    const userLevel = userRole === 'USER' ? 0 : userRole === 'ADMIN' ? 1 : 2;\n\n    if (myLevel < userLevel) {\n      throw new Error('You do not have permission to delete this user');\n    }\n\n    return this._organizationRepository.deleteTeamMember(org.id, userId);\n  }\n\n  disableOrEnableNonSuperAdminUsers(orgId: string, disable: boolean) {\n    return this._organizationRepository.disableOrEnableNonSuperAdminUsers(\n      orgId,","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts#L147-L183","documentation":"Thrown as a plain Error (resulting in HTTP 500 unless caught) when deleting a team member whose user-organization record doesn't include the target org — i.e. the userId is not a member of this organization at all.","triggerScenarios":"Calling deleteTeamMember with a userId that never joined, already left, or belongs to a different org; stale UI showing a removed member; double-delete from concurrent requests.","commonSituations":"Member list is stale after a prior removal; admin removes the same user in two tabs; userId mismatch (e.g. passing invite id or the wrong user's id); eventual-consistency lag between removal and list refresh.","solutions":["Refresh the member list and confirm the user is currently in this org before deleting","Make the delete flow idempotent — treat 'not a member' as success","Verify you're passing the correct userId (not an inviteId or orgUserId)"],"exampleFix":"// before\nawait deleteTeamMember(org, userId);\n// after\nconst members = await listMembers(org.id);\nif (members.some((m) => m.userId === userId)) {\n  await deleteTeamMember(org, userId);\n}","handlingStrategy":"validation","validationCode":"const members = await listMembers(org.id);\nif (!members.some((m) => m.userId === userId)) return; // nothing to delete","typeGuard":"const isMemberOf = (userOrgs: {id: string}[], orgId: string): boolean => userOrgs.some((o) => o.id === orgId);","tryCatchPattern":"try { await deleteTeamMember(org, userId); } catch (e) { if (/not part of this organization/.test(e.message)) return; // idempotent no-op throw e; }","preventionTips":["Refresh member state before delete actions","Treat removal as idempotent to survive double-clicks and stale UI"],"tags":["team-members","not-a-member","delete"],"backgroundTag":"member-not-in-organization","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}