feat: integrate user usage into apis (#5075)

This commit is contained in:
DarkSky
2023-12-14 09:50:36 +00:00
parent 63de73a815
commit ad23ead5e4
36 changed files with 984 additions and 282 deletions

View File

@@ -1,12 +1,39 @@
import {
CommonFeature,
FeatureKind,
Features,
FeatureType,
upsertFeature,
} from '../../modules/features';
import { Quotas } from '../../modules/quota';
} from '../../modules/features/types';
import { Quotas } from '../../modules/quota/types';
import { PrismaService } from '../../prisma';
// upgrade features from lower version to higher version
async function upsertFeature(
db: PrismaService,
feature: CommonFeature
): Promise<void> {
const hasEqualOrGreaterVersion =
(await db.features.count({
where: {
feature: feature.feature,
version: {
gte: feature.version,
},
},
})) > 0;
// will not update exists version
if (!hasEqualOrGreaterVersion) {
await db.features.create({
data: {
feature: feature.feature,
type: feature.type,
version: feature.version,
configs: feature.configs,
},
});
}
}
export class UserFeaturesInit1698652531198 {
// do the migration
static async up(db: PrismaService) {