-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(team-plans): track departed member usage so value not lost #2118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ndition, other improvements
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR implements tracking of departed member usage for team plans to ensure organizations are properly billed for usage incurred before members leave. Previously, when a member was removed from an organization, their Key Changes:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Admin as Admin/Owner
participant API as DELETE /api/organizations/[id]/members/[memberId]
participant DB as Database
participant Billing as calculateSubscriptionOverage()
participant Webhook as Invoice Webhook Handler
Note over Admin,API: Member Removal Flow
Admin->>API: DELETE request to remove member
API->>DB: Query member role
alt is owner
API-->>Admin: Error: Cannot remove owner
end
API->>DB: SELECT currentPeriodCost FROM userStats WHERE userId = memberId
DB-->>API: Return departed member's usage
alt usage > 0
API->>DB: UPDATE organization SET departedMemberUsage = departedMemberUsage + usage
DB-->>API: Usage accumulated
end
API->>DB: DELETE FROM member WHERE userId = memberId
DB-->>API: Member removed
API-->>Admin: Success response
Note over Billing,Webhook: Billing Calculation Flow
Billing->>DB: SELECT userId FROM member WHERE organizationId = orgId
DB-->>Billing: Return current members
loop For each member
Billing->>DB: Get member's currentPeriodCost
DB-->>Billing: Return usage
end
Billing->>DB: SELECT departedMemberUsage FROM organization
DB-->>Billing: Return departed member usage
Billing->>Billing: totalUsage = currentMemberUsage + departedMemberUsage
Billing->>Billing: Calculate overage = max(0, totalUsage - baseSubscriptionAmount)
Note over Webhook: End of Billing Period
Webhook->>DB: SELECT members for organization
loop For each member
Webhook->>DB: UPDATE userStats SET currentPeriodCost = '0'
end
Webhook->>DB: UPDATE organization SET departedMemberUsage = '0'
DB-->>Webhook: Usage reset for new period
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 files reviewed, no comments
… sendgrid, linkedin, more tools (#2148) * feat(tools): added smtp, sendgrid, mailgun, linkedin, fixed permissions in context menu (#2133) * feat(tools): added twilio sendgrid integration * feat(tools): added smtp, sendgrid, mailgun, fixed permissions in context menu * added top level mocks for sporadically failing tests * incr type safety * fix(team-plans): track departed member usage so value not lost (#2118) * fix(team-plans): track departed member usage so value not lost * reset usage to 0 when they leave team * prep merge with stagig * regen migrations * fix org invite + ws selection' --------- Co-authored-by: Waleed <[email protected]> * feat(i18n): update translations (#2134) Co-authored-by: waleedlatif1 <[email protected]> * feat(creators): add verification for creators (#2135) * feat(tools): added apify block/tools (#2136) * feat(tools): added apify * cleanup * feat(i18n): update translations (#2137) Co-authored-by: waleedlatif1 <[email protected]> * feat(env): added more optional env var examples (#2138) * feat(statuspage): added statuspage, updated list of tools in footer, renamed routes (#2139) * feat(statuspage): added statuspage, updated list of tools in footer, renamed routes * ack PR comments * feat(tools): add generic search tool (#2140) * feat(i18n): update translations (#2141) * fix(sdks): bump sdk versions (#2142) * fix(webhooks): count test webhooks towards usage limit (#2143) * fix(bill): add requestId to webhook processing (#2144) * improvement(subflow): remove all associated edges when moving a block into a subflow (#2145) * improvement(subflow): remove all associated edges when moving a block into a subflow * ack PR comments * fix(polling): mark webhook failed on webhook trigger errors (#2146) * fix(deps): declare core transient deps explicitly (#2147) * fix(deps): declare core transient deps explicitly * ack PR comments --------- Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: waleedlatif1 <[email protected]>
Summary
Must track departed member usage so that is billed by the org.
Type of Change
Testing
Tested manually
Checklist