Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
createTenantSubscription as persistTenantSubscription,
|
||||
getTenantSubscription as readTenantSubscription,
|
||||
updateTenantSubscriptionCustomerId as persistTenantSubscriptionCustomerId,
|
||||
type TenantSubscriptionWithDetails,
|
||||
} from "@toolctrl/db/subscriptions.server";
|
||||
import { clearTenantSubscriptionCache } from "~/utils/services/.server/subscriptionService";
|
||||
|
||||
export { getTenantSubscription, getTenantSubscriptions, type TenantSubscriptionWithDetails } from "@toolctrl/db/subscriptions.server";
|
||||
|
||||
export async function getOrPersistTenantSubscription(tenantId: string): Promise<TenantSubscriptionWithDetails> {
|
||||
const subscription = await readTenantSubscription(tenantId);
|
||||
|
||||
if (!subscription) {
|
||||
return await createTenantSubscription(tenantId, "");
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
|
||||
export async function createTenantSubscription(tenantId: string, stripeCustomerId: string) {
|
||||
const item = await persistTenantSubscription({ tenantId, stripeCustomerId });
|
||||
// Cross-replica purge: clearTenantSubscriptionCache publishes on the
|
||||
// subscription pub/sub channel so peer web replicas drop their L1 too.
|
||||
clearTenantSubscriptionCache(tenantId);
|
||||
return item;
|
||||
}
|
||||
|
||||
export async function updateTenantSubscriptionCustomerId(tenantId: string, data: { stripeCustomerId: string }) {
|
||||
const item = await persistTenantSubscriptionCustomerId(tenantId, data);
|
||||
clearTenantSubscriptionCache(tenantId);
|
||||
return item;
|
||||
}
|
||||
Reference in new issue
Block a user