mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
fix(server): dirty data handle (#15034)
#### PR Dependency Tree * **PR #15034** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Consolidated subscription visibility and “active” selection logic so all subscription queries use a shared, consistent filter across the platform. * **Tests** * Added a test to ensure expired subscriptions are excluded from active subscription results. * Updated test fixtures to differentiate expired, unexpired, and onetime subscriptions for more accurate coverage. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/15034?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { PrismaClient, UserStripeCustomer } from '@prisma/client';
|
||||
import { type Prisma, PrismaClient, UserStripeCustomer } from '@prisma/client';
|
||||
import Stripe from 'stripe';
|
||||
import { z } from 'zod';
|
||||
|
||||
@@ -13,9 +13,40 @@ import {
|
||||
LookupKey,
|
||||
SubscriptionPlan,
|
||||
SubscriptionRecurring,
|
||||
SubscriptionStatus,
|
||||
SubscriptionVariant,
|
||||
} from '../types';
|
||||
|
||||
export function validSubscriptionPeriodWhere(
|
||||
now = new Date()
|
||||
): Prisma.SubscriptionWhereInput {
|
||||
return { OR: [{ end: null }, { end: { gt: now } }] };
|
||||
}
|
||||
|
||||
export function activeSubscriptionWhere(
|
||||
now = new Date()
|
||||
): Prisma.SubscriptionWhereInput {
|
||||
return {
|
||||
status: { in: [SubscriptionStatus.Active, SubscriptionStatus.Trialing] },
|
||||
...validSubscriptionPeriodWhere(now),
|
||||
};
|
||||
}
|
||||
|
||||
export function visibleSubscriptionWhere(
|
||||
now = new Date()
|
||||
): Prisma.SubscriptionWhereInput {
|
||||
return {
|
||||
status: {
|
||||
in: [
|
||||
SubscriptionStatus.Active,
|
||||
SubscriptionStatus.Trialing,
|
||||
SubscriptionStatus.PastDue,
|
||||
],
|
||||
},
|
||||
...validSubscriptionPeriodWhere(now),
|
||||
};
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
stripeSubscriptionId: string | null;
|
||||
stripeScheduleId: string | null;
|
||||
|
||||
Reference in New Issue
Block a user