mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 14:56:59 +08:00
feat: check quota correctly (#6561)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
import { FeatureKind } from '../../../core/features';
|
||||
import { Quotas } from '../../../core/quota/schema';
|
||||
import { getLatestQuota } from '../../../core/quota/schema';
|
||||
import { Quota, QuotaType } from '../../../core/quota/types';
|
||||
import { upsertFeature } from './user-features';
|
||||
|
||||
@@ -21,10 +21,10 @@ export async function upgradeQuotaVersion(
|
||||
});
|
||||
|
||||
// find all users that have old free plan
|
||||
const userIds = await db.user.findMany({
|
||||
const userIds = await tx.user.findMany({
|
||||
where: {
|
||||
features: {
|
||||
every: {
|
||||
some: {
|
||||
feature: {
|
||||
type: FeatureKind.Quota,
|
||||
feature: quota.feature,
|
||||
@@ -65,13 +65,19 @@ export async function upgradeQuotaVersion(
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertLatestQuotaVersion(
|
||||
db: PrismaClient,
|
||||
type: QuotaType
|
||||
) {
|
||||
const latestQuota = getLatestQuota(type);
|
||||
await upsertFeature(db, latestQuota);
|
||||
}
|
||||
|
||||
export async function upgradeLatestQuotaVersion(
|
||||
db: PrismaClient,
|
||||
type: QuotaType,
|
||||
reason: string
|
||||
) {
|
||||
const quota = Quotas.filter(f => f.feature === type);
|
||||
quota.sort((a, b) => b.version - a.version);
|
||||
const latestQuota = quota[0];
|
||||
const latestQuota = getLatestQuota(type);
|
||||
await upgradeQuotaVersion(db, latestQuota, reason);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user