-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTeamPresenter.server.ts
More file actions
43 lines (38 loc) · 1.36 KB
/
TeamPresenter.server.ts
File metadata and controls
43 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { getTeamMembersAndInvites } from "~/models/member.server";
import { getCurrentPlan, getLimit, getPlans } from "~/services/platform.v3.server";
import { BasePresenter } from "./v3/basePresenter.server";
export class TeamPresenter extends BasePresenter {
public async call({ userId, organizationId }: { userId: string; organizationId: string }) {
const result = await getTeamMembersAndInvites({
userId,
organizationId,
});
if (!result) {
return;
}
const [baseLimit, currentPlan, plans] = await Promise.all([
getLimit(organizationId, "teamMembers", 100_000_000),
getCurrentPlan(organizationId),
getPlans(),
]);
const canPurchaseSeats =
currentPlan?.v3Subscription?.plan?.limits.teamMembers.canExceed === true;
const extraSeats = currentPlan?.v3Subscription?.addOns?.seats?.purchased ?? 0;
const maxSeatQuota = currentPlan?.v3Subscription?.addOns?.seats?.quota ?? 0;
const planSeatLimit = currentPlan?.v3Subscription?.plan?.limits.teamMembers.number ?? 0;
const seatPricing = plans?.addOnPricing.seats ?? null;
const limit = baseLimit + extraSeats;
return {
...result,
limits: {
used: result.members.length + result.invites.length,
limit,
},
canPurchaseSeats,
extraSeats,
seatPricing,
maxSeatQuota,
planSeatLimit,
};
}
}