refactor(workspace, users, billing): remove default workspace + rename (#9360)

Replaced user-based parameterization with workspace-focused logic across
seed scripts, mocks, and billing services. Removed redundant `user`
references and standardized to `workspace` to align with updated
business rules. Adjusted mock data and tests to reflect these changes.

Fix https://github.com/twentyhq/twenty/issues/9295
This commit is contained in:
Antoine Moreaux
2025-01-06 12:33:57 +01:00
committed by GitHub
parent 25083e5405
commit 3eb7ec909e
12 changed files with 35 additions and 51 deletions

View File

@ -37,9 +37,8 @@ export class BillingResolver {
}
@Query(() => SessionEntity)
@UseGuards(WorkspaceAuthGuard, UserAuthGuard)
@UseGuards(WorkspaceAuthGuard)
async billingPortalSession(
@AuthUser() user: User,
@AuthWorkspace() workspace: Workspace,
@Args() { returnUrlPath }: BillingSessionInput,
) {
@ -89,8 +88,8 @@ export class BillingResolver {
@Mutation(() => UpdateBillingEntity)
@UseGuards(WorkspaceAuthGuard)
async updateBillingSubscription(@AuthUser() user: User) {
await this.billingSubscriptionService.applyBillingSubscription(user);
async updateBillingSubscription(@AuthWorkspace() workspace: Workspace) {
await this.billingSubscriptionService.applyBillingSubscription(workspace);
return { success: true };
}

View File

@ -3,7 +3,6 @@ import { InjectRepository } from '@nestjs/typeorm';
import assert from 'assert';
import { User } from '@sentry/node';
import Stripe from 'stripe';
import { Not, Repository } from 'typeorm';
@ -15,6 +14,7 @@ import { SubscriptionInterval } from 'src/engine/core-modules/billing/enums/bill
import { SubscriptionStatus } from 'src/engine/core-modules/billing/enums/billing-subscription-status.enum';
import { StripeService } from 'src/engine/core-modules/billing/stripe/stripe.service';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
@Injectable()
export class BillingSubscriptionService {
@ -114,9 +114,9 @@ export class BillingSubscriptionService {
return entitlement.value;
}
async applyBillingSubscription(user: User) {
async applyBillingSubscription(workspace: Workspace) {
const billingSubscription = await this.getCurrentBillingSubscriptionOrThrow(
{ workspaceId: user.defaultWorkspaceId },
{ workspaceId: workspace.id },
);
const newInterval =
@ -125,9 +125,7 @@ export class BillingSubscriptionService {
: SubscriptionInterval.Year;
const billingSubscriptionItem =
await this.getCurrentBillingSubscriptionItemOrThrow(
user.defaultWorkspaceId,
);
await this.getCurrentBillingSubscriptionItemOrThrow(workspace.id);
const productPrice = await this.stripeService.getStripePrice(
AvailableProduct.BasePlan,