Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+32
@@ -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