11import { AppConfig } from "@/config/type" ;
22import { API_VERSIONS_VALUES } from "@/lib/api-versions" ;
3+ import { ApiAuthGuardOnlyAllow } from "@/modules/auth/decorators/api-auth-guard-only-allow.decorator" ;
34import { MembershipRoles } from "@/modules/auth/decorators/roles/membership-roles.decorator" ;
4- import { NextAuthGuard } from "@/modules/auth/guards/next -auth/next -auth.guard" ;
5+ import { ApiAuthGuard } from "@/modules/auth/guards/api -auth/api -auth.guard" ;
56import { OrganizationRolesGuard } from "@/modules/auth/guards/organization-roles/organization-roles.guard" ;
67import { SubscribeToPlanInput } from "@/modules/billing/controllers/inputs/subscribe-to-plan.input" ;
78import { CheckPlatformBillingResponseDto } from "@/modules/billing/controllers/outputs/CheckPlatformBillingResponse.dto" ;
89import { SubscribeTeamToBillingResponseDto } from "@/modules/billing/controllers/outputs/SubscribeTeamToBillingResponse.dto" ;
10+ import { IsUserInBillingOrg } from "@/modules/billing/guards/is-user-in-billing-org" ;
911import { IBillingService } from "@/modules/billing/interfaces/billing-service.interface" ;
1012import { StripeService } from "@/modules/stripe/stripe.service" ;
1113import {
@@ -49,8 +51,9 @@ export class BillingController {
4951 }
5052
5153 @Get ( "/:teamId/check" )
52- @UseGuards ( NextAuthGuard , OrganizationRolesGuard )
54+ @UseGuards ( ApiAuthGuard , OrganizationRolesGuard , IsUserInBillingOrg )
5355 @MembershipRoles ( [ "OWNER" , "ADMIN" , "MEMBER" ] )
56+ @ApiAuthGuardOnlyAllow ( [ "NEXT_AUTH" ] )
5457 async checkTeamBilling (
5558 @Param ( "teamId" , ParseIntPipe ) teamId : number
5659 ) : Promise < ApiResponse < CheckPlatformBillingResponseDto > > {
@@ -66,8 +69,9 @@ export class BillingController {
6669 }
6770
6871 @Post ( "/:teamId/subscribe" )
69- @UseGuards ( NextAuthGuard , OrganizationRolesGuard )
72+ @UseGuards ( ApiAuthGuard , OrganizationRolesGuard , IsUserInBillingOrg )
7073 @MembershipRoles ( [ "OWNER" , "ADMIN" ] )
74+ @ApiAuthGuardOnlyAllow ( [ "NEXT_AUTH" ] )
7175 async subscribeTeamToStripe (
7276 @Param ( "teamId" ) teamId : number ,
7377 @Body ( ) input : SubscribeToPlanInput
@@ -84,8 +88,9 @@ export class BillingController {
8488 }
8589
8690 @Post ( "/:teamId/upgrade" )
87- @UseGuards ( NextAuthGuard , OrganizationRolesGuard )
91+ @UseGuards ( ApiAuthGuard , OrganizationRolesGuard , IsUserInBillingOrg )
8892 @MembershipRoles ( [ "OWNER" , "ADMIN" ] )
93+ @ApiAuthGuardOnlyAllow ( [ "NEXT_AUTH" ] )
8994 async upgradeTeamBillingInStripe (
9095 @Param ( "teamId" ) teamId : number ,
9196 @Body ( ) input : SubscribeToPlanInput
@@ -100,13 +105,12 @@ export class BillingController {
100105 } ;
101106 }
102107
103- @Delete ( "/:organizationId /unsubscribe" )
104- @UseGuards ( NextAuthGuard , OrganizationRolesGuard )
108+ @Delete ( "/:teamId /unsubscribe" )
109+ @UseGuards ( ApiAuthGuard , OrganizationRolesGuard , IsUserInBillingOrg )
105110 @MembershipRoles ( [ "OWNER" , "ADMIN" ] )
106- async cancelTeamSubscriptionInStripe (
107- @Param ( "organizationId" ) organizationId : number
108- ) : Promise < ApiResponse > {
109- await this . billingService . cancelTeamSubscription ( organizationId ) ;
111+ @ApiAuthGuardOnlyAllow ( [ "NEXT_AUTH" ] )
112+ async cancelTeamSubscriptionInStripe ( @Param ( "teamId" ) teamId : number ) : Promise < ApiResponse > {
113+ await this . billingService . cancelTeamSubscription ( teamId ) ;
110114
111115 return {
112116 status : "success" ,
0 commit comments