()
| 47 | ); |
| 48 | |
| 49 | export const leaveOrg = async (): Promise<{ success: boolean } | ServiceError> => sew(() => |
| 50 | withAuth(async ({ user, org, prisma }) => { |
| 51 | const guardError = await _removeUserFromOrg(prisma, { |
| 52 | orgId: org.id, |
| 53 | userId: user.id, |
| 54 | lastOwnerMessage: "You are the last owner of this organization. Promote another member to owner before leaving.", |
| 55 | }); |
| 56 | |
| 57 | if (guardError) { |
| 58 | return guardError; |
| 59 | } |
| 60 | |
| 61 | await createAudit({ |
| 62 | action: "org.member_left", |
| 63 | actor: { id: user.id, type: "user" }, |
| 64 | target: { id: user.id, type: "user" }, |
| 65 | orgId: org.id, |
| 66 | metadata: { |
| 67 | message: `${user.id} left the organization`, |
| 68 | }, |
| 69 | }); |
| 70 | |
| 71 | return { |
| 72 | success: true, |
| 73 | } |
| 74 | })); |
| 75 | |
| 76 | |
| 77 | const _removeUserFromOrg = async ( |
no test coverage detected