mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 21:38:44 +08:00
feat(server): delay subscription after invitation accepted or approved (#11992)
This commit is contained in:
@@ -274,18 +274,21 @@ export class WorkspaceSubscriptionManager extends SubscriptionManager {
|
||||
}
|
||||
|
||||
@OnEvent('workspace.members.updated')
|
||||
async onMembersUpdated({
|
||||
workspaceId,
|
||||
count,
|
||||
}: Events['workspace.members.updated']) {
|
||||
async onMembersUpdated({ workspaceId }: Events['workspace.members.updated']) {
|
||||
const count = await this.models.workspaceUser.chargedCount(workspaceId);
|
||||
const subscription = await this.getSubscription({
|
||||
plan: SubscriptionPlan.Team,
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
if (!subscription || !subscription.stripeSubscriptionId) {
|
||||
if (
|
||||
!subscription ||
|
||||
!subscription.stripeSubscriptionId ||
|
||||
count === subscription.quantity
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stripeSubscription = await this.stripe.subscriptions.retrieve(
|
||||
subscription.stripeSubscriptionId
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { OnEvent } from '../../base';
|
||||
import { WorkspaceService } from '../../core/workspaces/resolvers';
|
||||
import { EventBus, OnEvent } from '../../base';
|
||||
import { WorkspaceService } from '../../core/workspaces';
|
||||
import { Models } from '../../models';
|
||||
import { SubscriptionPlan } from './types';
|
||||
|
||||
@@ -9,7 +9,8 @@ import { SubscriptionPlan } from './types';
|
||||
export class QuotaOverride {
|
||||
constructor(
|
||||
private readonly workspace: WorkspaceService,
|
||||
private readonly models: Models
|
||||
private readonly models: Models,
|
||||
private readonly event: EventBus
|
||||
) {}
|
||||
|
||||
@OnEvent('workspace.subscription.activated')
|
||||
@@ -30,7 +31,10 @@ export class QuotaOverride {
|
||||
memberLimit: quantity,
|
||||
}
|
||||
);
|
||||
await this.models.workspaceUser.refresh(workspaceId, quantity);
|
||||
this.event.emit('workspace.members.allocateSeats', {
|
||||
workspaceId,
|
||||
quantity,
|
||||
});
|
||||
if (!isTeam) {
|
||||
// this event will triggered when subscription is activated or changed
|
||||
// we only send emails when the team workspace is activated
|
||||
|
||||
Reference in New Issue
Block a user