Files
cfw-autumn/shared/api/customers/utils/apiSubjectToOverageAllowed.ts
2026-03-30 15:25:40 +01:00

26 lines
691 B
TypeScript

import type { ApiOverageAllowed } from "@api/billingControls";
import type { Feature } from "@models/featureModels/featureModels";
import type { ApiSubjectV0 } from "../apiSubjectV0";
export const apiSubjectToOverageAllowedControl = ({
subject,
feature,
}: {
subject: ApiSubjectV0;
feature: Feature;
}): ApiOverageAllowed | undefined => {
if (!("billing_controls" in subject) || !subject.billing_controls) {
return undefined;
}
if (!("overage_allowed" in subject.billing_controls)) {
return undefined;
}
const overageAllowed = subject.billing_controls.overage_allowed ?? [];
return overageAllowed.find(
(entry) => entry.enabled && entry.feature_id === feature.id,
);
};