47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
/**
|
|
* Seat-type derivation (Fundament C).
|
|
*
|
|
* A "seat" is the billing bucket / default UI mode a workspace member occupies:
|
|
* `office` = back-office desk work, `field` = on-site (Baustelle) work. One human
|
|
* occupies exactly one seat.
|
|
*
|
|
* `SeatType` mirrors the Prisma enum of the same name (`Role.seatCategory`,
|
|
* `TenantUser.seatType`). It is redeclared here as a string union so this
|
|
* entitlements package stays dependency-free (same convention as `FeatureKey`).
|
|
* The app-side server helper feeds the real Prisma enum values into
|
|
* `deriveSeatType`, so any divergence between the two surfaces as a compile error
|
|
* there rather than silently going unnoticed.
|
|
*/
|
|
export type SeatType = "office" | "field";
|
|
|
|
export const SEAT_TYPES = {
|
|
office: "office",
|
|
field: "field",
|
|
} as const satisfies Record<SeatType, SeatType>;
|
|
|
|
export interface DeriveSeatTypeInput {
|
|
/** Seat category of every role the user holds in the tenant. */
|
|
readonly roleSeatCategories: readonly SeatType[];
|
|
/**
|
|
* Explicit `TenantUser.seatType` admin billing override. `null`/`undefined`
|
|
* means "no override — derive from the roles".
|
|
*/
|
|
readonly override?: SeatType | null;
|
|
}
|
|
|
|
/**
|
|
* Effective seat of a member:
|
|
* 1. an explicit admin override always wins, otherwise
|
|
* 2. any `office` role promotes the member to the (more expensive) office seat,
|
|
* 3. and a member with only field roles — or no roles at all — stays on a field seat.
|
|
*
|
|
* "One human, one seat; every office role means an office desk — the pricier one.
|
|
* No middle ground."
|
|
*/
|
|
export function deriveSeatType(input: DeriveSeatTypeInput): SeatType {
|
|
if (input.override != null) {
|
|
return input.override;
|
|
}
|
|
return input.roleSeatCategories.some((category) => category === SEAT_TYPES.office) ? SEAT_TYPES.office : SEAT_TYPES.field;
|
|
}
|