@@ -11,6 +11,7 @@ import { TeamSubscription2 } from "@gitpod/gitpod-protocol/lib/team-subscription
1111import { inject , injectable } from "inversify" ;
1212import { SubscriptionModel } from "./subscription-model" ;
1313import { SubscriptionService } from "./subscription-service" ;
14+ import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
1415
1516@injectable ( )
1617export class TeamSubscription2Service {
@@ -19,13 +20,15 @@ export class TeamSubscription2Service {
1920 @inject ( SubscriptionService ) protected readonly subscriptionService : SubscriptionService ;
2021
2122 async addAllTeamMemberSubscriptions ( ts2 : TeamSubscription2 ) : Promise < void > {
23+ log . info ( `addAllTeamMemberSubscriptions: ts2=${ JSON . stringify ( ts2 ) } ` ) ;
2224 const members = await this . teamDB . findMembersByTeam ( ts2 . teamId ) ;
2325 for ( const member of members ) {
2426 await this . addTeamMemberSubscription ( ts2 , member . userId ) ;
2527 }
2628 }
2729
2830 async addTeamMemberSubscription ( ts2 : TeamSubscription2 , userId : string ) : Promise < void > {
31+ log . info ( `addTeamMemberSubscription: ts2=${ JSON . stringify ( ts2 ) } userId=${ JSON . stringify ( userId ) } ` ) ;
2932 const membership = await this . teamDB . findTeamMembership ( userId , ts2 . teamId ) ;
3033 if ( ! membership ) {
3134 throw new Error ( `Could not find membership for user '${ userId } ' in team '${ ts2 . teamId } '` ) ;
@@ -39,6 +42,7 @@ export class TeamSubscription2Service {
3942 }
4043
4144 protected async addSubscription ( db : AccountingDB , userId : string , planId : string , teamMembershipId : string , startDate : string , amount : number , firstMonthAmount ?: number , endDate ?: string , cancelationDate ?: string ) {
45+ log . info ( `addSubscription: userId=${ userId } planId=${ planId } teamMembershipId=${ teamMembershipId } startDate=${ startDate } amount=${ amount } ` ) ;
4246 const model = await this . loadSubscriptionModel ( db , userId ) ;
4347 const subscription = Subscription . create ( {
4448 userId,
@@ -56,6 +60,7 @@ export class TeamSubscription2Service {
5660 }
5761
5862 async cancelAllTeamMemberSubscriptions ( ts2 : TeamSubscription2 , date : Date ) : Promise < void > {
63+ log . info ( `cancelAllTeamMemberSubscriptions: ts2=${ JSON . stringify ( ts2 ) } date=${ date . toISOString ( ) } ` ) ;
5964 const members = await this . teamDB . findMembersByTeam ( ts2 . teamId ) ;
6065 for ( const member of members ) {
6166 const membership = await this . teamDB . findTeamMembership ( member . userId , ts2 . teamId ) ;
@@ -67,13 +72,15 @@ export class TeamSubscription2Service {
6772 }
6873
6974 async cancelTeamMemberSubscription ( ts2 : TeamSubscription2 , userId : string , teamMemberShipId : string , date : Date ) : Promise < void > {
75+ log . info ( `cancelTeamMemberSubscription: ts2=${ JSON . stringify ( ts2 ) } userId=${ userId } teamMemberShipId=${ teamMemberShipId } date=${ date . toISOString ( ) } ` ) ;
7076 const { endDate } = Subscription . calculateCurrentPeriod ( ts2 . startDate , date ) ;
7177 return this . accountingDb . transaction ( async ( db ) => {
7278 await this . cancelSubscription ( db , userId , ts2 . planId , teamMemberShipId , endDate ) ;
7379 } ) ;
7480 }
7581
7682 protected async cancelSubscription ( db : AccountingDB , userId : string , planId : string , teamMembershipId : string , cancellationDate : string ) {
83+ log . info ( `cancelSubscription: userId=${ userId } planId=${ planId } teamMembershipId=${ teamMembershipId } cancellationDate=${ cancellationDate } ` ) ;
7784 const model = await this . loadSubscriptionModel ( db , userId ) ;
7885 const subscription = model . findSubscriptionByTeamMembershipId ( teamMembershipId ) ;
7986 if ( ! subscription ) {
0 commit comments