@@ -11,6 +11,7 @@ import { TeamSubscription2 } from "@gitpod/gitpod-protocol/lib/team-subscription
11
11
import { inject , injectable } from "inversify" ;
12
12
import { SubscriptionModel } from "./subscription-model" ;
13
13
import { SubscriptionService } from "./subscription-service" ;
14
+ import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
14
15
15
16
@injectable ( )
16
17
export class TeamSubscription2Service {
@@ -19,13 +20,15 @@ export class TeamSubscription2Service {
19
20
@inject ( SubscriptionService ) protected readonly subscriptionService : SubscriptionService ;
20
21
21
22
async addAllTeamMemberSubscriptions ( ts2 : TeamSubscription2 ) : Promise < void > {
23
+ log . info ( `addAllTeamMemberSubscriptions: ts2=${ JSON . stringify ( ts2 ) } ` ) ;
22
24
const members = await this . teamDB . findMembersByTeam ( ts2 . teamId ) ;
23
25
for ( const member of members ) {
24
26
await this . addTeamMemberSubscription ( ts2 , member . userId ) ;
25
27
}
26
28
}
27
29
28
30
async addTeamMemberSubscription ( ts2 : TeamSubscription2 , userId : string ) : Promise < void > {
31
+ log . info ( `addTeamMemberSubscription: ts2=${ JSON . stringify ( ts2 ) } userId=${ JSON . stringify ( userId ) } ` ) ;
29
32
const membership = await this . teamDB . findTeamMembership ( userId , ts2 . teamId ) ;
30
33
if ( ! membership ) {
31
34
throw new Error ( `Could not find membership for user '${ userId } ' in team '${ ts2 . teamId } '` ) ;
@@ -39,6 +42,7 @@ export class TeamSubscription2Service {
39
42
}
40
43
41
44
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 } ` ) ;
42
46
const model = await this . loadSubscriptionModel ( db , userId ) ;
43
47
const subscription = Subscription . create ( {
44
48
userId,
@@ -56,6 +60,7 @@ export class TeamSubscription2Service {
56
60
}
57
61
58
62
async cancelAllTeamMemberSubscriptions ( ts2 : TeamSubscription2 , date : Date ) : Promise < void > {
63
+ log . info ( `cancelAllTeamMemberSubscriptions: ts2=${ JSON . stringify ( ts2 ) } date=${ date . toISOString ( ) } ` ) ;
59
64
const members = await this . teamDB . findMembersByTeam ( ts2 . teamId ) ;
60
65
for ( const member of members ) {
61
66
const membership = await this . teamDB . findTeamMembership ( member . userId , ts2 . teamId ) ;
@@ -67,13 +72,15 @@ export class TeamSubscription2Service {
67
72
}
68
73
69
74
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 ( ) } ` ) ;
70
76
const { endDate } = Subscription . calculateCurrentPeriod ( ts2 . startDate , date ) ;
71
77
return this . accountingDb . transaction ( async ( db ) => {
72
78
await this . cancelSubscription ( db , userId , ts2 . planId , teamMemberShipId , endDate ) ;
73
79
} ) ;
74
80
}
75
81
76
82
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 } ` ) ;
77
84
const model = await this . loadSubscriptionModel ( db , userId ) ;
78
85
const subscription = model . findSubscriptionByTeamMembershipId ( teamMembershipId ) ;
79
86
if ( ! subscription ) {
0 commit comments