Browse Source

Introduce interface

pull/5791/head
Thomas Kaul 2 weeks ago
parent
commit
87f4f3c395
  1. 7
      apps/api/src/app/subscription/subscription.controller.ts
  2. 7
      apps/api/src/app/subscription/subscription.service.ts
  3. 7
      apps/client/src/app/components/user-account-membership/user-account-membership.component.ts
  4. 7
      apps/client/src/app/pages/pricing/pricing-page.component.ts
  5. 14
      apps/client/src/app/services/data.service.ts
  6. 2
      libs/common/src/lib/interfaces/index.ts

7
apps/api/src/app/subscription/subscription.controller.ts

@ -5,7 +5,10 @@ import {
DEFAULT_LANGUAGE_CODE,
PROPERTY_COUPONS
} from '@ghostfolio/common/config';
import { Coupon } from '@ghostfolio/common/interfaces';
import {
Coupon,
CreateStripeCheckoutSessionResponse
} from '@ghostfolio/common/interfaces';
import type { RequestWithUser } from '@ghostfolio/common/types';
import {
@ -113,7 +116,7 @@ export class SubscriptionController {
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async createCheckoutSession(
@Body() { couponId, priceId }: { couponId?: string; priceId: string }
) {
): Promise<CreateStripeCheckoutSessionResponse> {
try {
return this.subscriptionService.createCheckoutSession({
couponId,

7
apps/api/src/app/subscription/subscription.service.ts

@ -6,7 +6,10 @@ import {
PROPERTY_STRIPE_CONFIG
} from '@ghostfolio/common/config';
import { parseDate } from '@ghostfolio/common/helper';
import { SubscriptionOffer } from '@ghostfolio/common/interfaces';
import {
CreateStripeCheckoutSessionResponse,
SubscriptionOffer
} from '@ghostfolio/common/interfaces';
import {
SubscriptionOfferKey,
UserWithSettings
@ -46,7 +49,7 @@ export class SubscriptionService {
couponId?: string;
priceId: string;
user: UserWithSettings;
}) {
}): Promise<CreateStripeCheckoutSessionResponse> {
const subscriptionOffers: {
[offer in SubscriptionOfferKey]: SubscriptionOffer;
} =

7
apps/client/src/app/components/user-account-membership/user-account-membership.component.ts

@ -108,7 +108,10 @@ export class GfUserAccountMembershipComponent implements OnDestroy {
public onCheckout() {
this.dataService
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId })
.createStripeCheckoutSession({
couponId: this.couponId,
priceId: this.priceId
})
.pipe(
catchError((error) => {
this.notificationService.alert({
@ -117,7 +120,7 @@ export class GfUserAccountMembershipComponent implements OnDestroy {
throw error;
}),
switchMap(({ sessionId }: { sessionId: string }) => {
switchMap(({ sessionId }) => {
return this.stripeService.redirectToCheckout({ sessionId });
})
)

7
apps/client/src/app/pages/pricing/pricing-page.component.ts

@ -134,9 +134,12 @@ export class GfPricingPageComponent implements OnDestroy, OnInit {
public onCheckout() {
this.dataService
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId })
.createStripeCheckoutSession({
couponId: this.couponId,
priceId: this.priceId
})
.pipe(
switchMap(({ sessionId }: { sessionId: string }) => {
switchMap(({ sessionId }) => {
return this.stripeService.redirectToCheckout({ sessionId });
}),
catchError((error) => {

14
apps/client/src/app/services/data.service.ts

@ -32,6 +32,7 @@ import {
AssetProfileIdentifier,
BenchmarkMarketDataDetailsResponse,
BenchmarkResponse,
CreateStripeCheckoutSessionResponse,
DataProviderHealthResponse,
Export,
Filter,
@ -169,17 +170,20 @@ export class DataService {
return params;
}
public createCheckoutSession({
public createStripeCheckoutSession({
couponId,
priceId
}: {
couponId?: string;
priceId: string;
}) {
return this.http.post('/api/v1/subscription/stripe/checkout-session', {
couponId,
priceId
});
return this.http.post<CreateStripeCheckoutSessionResponse>(
'/api/v1/subscription/stripe/checkout-session',
{
couponId,
priceId
}
);
}
public fetchAccount(aAccountId: string) {

2
libs/common/src/lib/interfaces/index.ts

@ -42,6 +42,7 @@ import type { AiPromptResponse } from './responses/ai-prompt-response.interface'
import type { ApiKeyResponse } from './responses/api-key-response.interface';
import type { BenchmarkMarketDataDetailsResponse } from './responses/benchmark-market-data-details-response.interface';
import type { BenchmarkResponse } from './responses/benchmark-response.interface';
import type { CreateStripeCheckoutSessionResponse } from './responses/create-stripe-checkout-session-response.interface';
import type { DataEnhancerHealthResponse } from './responses/data-enhancer-health-response.interface';
import type { DataProviderGhostfolioAssetProfileResponse } from './responses/data-provider-ghostfolio-asset-profile-response.interface';
import type { DataProviderGhostfolioStatusResponse } from './responses/data-provider-ghostfolio-status-response.interface';
@ -95,6 +96,7 @@ export {
BenchmarkProperty,
BenchmarkResponse,
Coupon,
CreateStripeCheckoutSessionResponse,
DataEnhancerHealthResponse,
DataProviderGhostfolioAssetProfileResponse,
DataProviderGhostfolioStatusResponse,

Loading…
Cancel
Save