Skip to content

Commit a2b2283

Browse files
jankeromnesroboquat
authored andcommitted
[payment] Auto-format chargebee/team-subscription-handler.ts
1 parent 1dd74d3 commit a2b2283

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

components/ee/payment-endpoint/src/chargebee/team-subscription-handler.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
* See License.enterprise.txt in the project root folder.
55
*/
66

7-
import { inject, injectable } from 'inversify';
7+
import { inject, injectable } from "inversify";
88

9-
import { TeamSubscriptionDB } from '@gitpod/gitpod-db/lib/team-subscription-db';
10-
import { log, LogContext } from '@gitpod/gitpod-protocol/lib/util/logging';
11-
import { Plans } from '@gitpod/gitpod-protocol/lib/plans';
12-
import { TeamSubscription } from '@gitpod/gitpod-protocol/lib/team-subscription-protocol';
13-
import { getCancelledAt, getStartDate } from './chargebee-subscription-helper';
14-
import { Chargebee as chargebee } from './chargebee-types';
15-
import { EventHandler } from './chargebee-event-handler';
9+
import { TeamSubscriptionDB } from "@gitpod/gitpod-db/lib/team-subscription-db";
10+
import { log, LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";
11+
import { Plans } from "@gitpod/gitpod-protocol/lib/plans";
12+
import { TeamSubscription } from "@gitpod/gitpod-protocol/lib/team-subscription-protocol";
13+
import { getCancelledAt, getStartDate } from "./chargebee-subscription-helper";
14+
import { Chargebee as chargebee } from "./chargebee-types";
15+
import { EventHandler } from "./chargebee-event-handler";
1616
import { TeamSubscriptionService } from "../accounting/team-subscription-service";
17-
import { Config } from '../config';
17+
import { Config } from "../config";
1818

1919
@injectable()
2020
export class TeamSubscriptionHandler implements EventHandler<chargebee.SubscriptionEventV2> {
@@ -23,7 +23,7 @@ export class TeamSubscriptionHandler implements EventHandler<chargebee.Subscript
2323
@inject(TeamSubscriptionService) protected readonly service: TeamSubscriptionService;
2424

2525
canHandle(event: chargebee.Event<any>): boolean {
26-
if (event.event_type.startsWith('subscription')) {
26+
if (event.event_type.startsWith("subscription")) {
2727
const evt = event as chargebee.Event<chargebee.SubscriptionEventV2>;
2828
const plan = Plans.getById(evt.content.subscription.plan_id);
2929
if (!plan) {
@@ -53,17 +53,23 @@ export class TeamSubscriptionHandler implements EventHandler<chargebee.Subscript
5353
return true;
5454
}
5555

56-
async mapToTeamSubscription(userId: string, eventType: chargebee.EventType, chargebeeSubscription: chargebee.Subscription) {
56+
async mapToTeamSubscription(
57+
userId: string,
58+
eventType: chargebee.EventType,
59+
chargebeeSubscription: chargebee.Subscription,
60+
) {
5761
await this.db.transaction(async (db) => {
5862
const subs = await db.findTeamSubscriptions({
5963
userId,
60-
paymentReference: chargebeeSubscription.id
64+
paymentReference: chargebeeSubscription.id,
6165
});
6266
if (subs.length === 0) {
6367
// Sanity check: If we try to create too many slots here we OOM, so we error instead.
6468
const quantity = chargebeeSubscription.plan_quantity;
6569
if (quantity > this.config.maxTeamSlotsOnCreation) {
66-
throw new Error(`(TS ${chargebeeSubscription.id}): nr of slots on creation (${quantity}) is higher than configured maximum (${this.config.maxTeamSlotsOnCreation}). Skipping creation!`);
70+
throw new Error(
71+
`(TS ${chargebeeSubscription.id}): nr of slots on creation (${quantity}) is higher than configured maximum (${this.config.maxTeamSlotsOnCreation}). Skipping creation!`,
72+
);
6773
}
6874

6975
const ts = TeamSubscription.create({
@@ -78,12 +84,12 @@ export class TeamSubscriptionHandler implements EventHandler<chargebee.Subscript
7884
await db.storeTeamSubscriptionEntry(ts);
7985
await this.service.addSlots(ts, quantity);
8086
} else {
81-
const oldSubscription = subs.find(s => s.paymentReference === chargebeeSubscription.id);
87+
const oldSubscription = subs.find((s) => s.paymentReference === chargebeeSubscription.id);
8288
if (!oldSubscription) {
8389
throw new Error(`Cannot find TeamSubscription for paymentReference ${chargebeeSubscription.id}!`);
8490
}
8591

86-
if (eventType === 'subscription_cancelled') {
92+
if (eventType === "subscription_cancelled") {
8793
const cancelledAt = getCancelledAt(chargebeeSubscription);
8894
oldSubscription.endDate = cancelledAt;
8995
await this.service.deactivateAllSlots(oldSubscription, new Date(cancelledAt));
@@ -97,4 +103,4 @@ export class TeamSubscriptionHandler implements EventHandler<chargebee.Subscript
97103
protected userContext(event: chargebee.Event<chargebee.SubscriptionEventV2>): LogContext {
98104
return { userId: event.content.subscription.customer_id };
99105
}
100-
}
106+
}

0 commit comments

Comments
 (0)