feat(server): add pro quota to dev user (#6532)

This commit is contained in:
EYHN
2024-04-12 06:45:18 +00:00
parent 1e12d4a2cb
commit 9e7a2fcf0e
3 changed files with 14 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { FeatureModule } from '../features';
import { QuotaModule } from '../quota';
import { UserModule } from '../user';
import { AuthController } from './controller';
import { AuthResolver } from './resolver';
@@ -8,7 +9,7 @@ import { AuthService } from './service';
import { TokenService, TokenType } from './token';
@Module({
imports: [FeatureModule, UserModule],
imports: [FeatureModule, UserModule, QuotaModule],
providers: [AuthService, AuthResolver, TokenService],
exports: [AuthService],
controllers: [AuthController],

View File

@@ -11,6 +11,8 @@ import { assign, omit } from 'lodash-es';
import { Config, CryptoHelper, MailService } from '../../fundamentals';
import { FeatureManagementService } from '../features/management';
import { QuotaService } from '../quota/service';
import { QuotaType } from '../quota/types';
import { UserService } from '../user/service';
import type { CurrentUser } from './current-user';
@@ -68,15 +70,21 @@ export class AuthService implements OnApplicationBootstrap {
private readonly db: PrismaClient,
private readonly mailer: MailService,
private readonly feature: FeatureManagementService,
private readonly quota: QuotaService,
private readonly user: UserService,
private readonly crypto: CryptoHelper
) {}
async onApplicationBootstrap() {
if (this.config.node.dev) {
await this.signUp('Dev User', 'dev@affine.pro', 'dev').catch(() => {
try {
const devUser = await this.signUp('Dev User', 'dev@affine.pro', 'dev');
if (devUser) {
await this.quota.switchUserQuota(devUser?.id, QuotaType.ProPlanV1);
}
} catch (e) {
// ignore
});
}
}
}