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

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

@ -6,7 +6,10 @@ import {
PROPERTY_STRIPE_CONFIG PROPERTY_STRIPE_CONFIG
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { parseDate } from '@ghostfolio/common/helper'; import { parseDate } from '@ghostfolio/common/helper';
import { SubscriptionOffer } from '@ghostfolio/common/interfaces'; import {
CreateStripeCheckoutSessionResponse,
SubscriptionOffer
} from '@ghostfolio/common/interfaces';
import { import {
SubscriptionOfferKey, SubscriptionOfferKey,
UserWithSettings UserWithSettings
@ -46,7 +49,7 @@ export class SubscriptionService {
couponId?: string; couponId?: string;
priceId: string; priceId: string;
user: UserWithSettings; user: UserWithSettings;
}) { }): Promise<CreateStripeCheckoutSessionResponse> {
const subscriptionOffers: { const subscriptionOffers: {
[offer in SubscriptionOfferKey]: SubscriptionOffer; [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() { public onCheckout() {
this.dataService this.dataService
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId }) .createStripeCheckoutSession({
couponId: this.couponId,
priceId: this.priceId
})
.pipe( .pipe(
catchError((error) => { catchError((error) => {
this.notificationService.alert({ this.notificationService.alert({
@ -117,7 +120,7 @@ export class GfUserAccountMembershipComponent implements OnDestroy {
throw error; throw error;
}), }),
switchMap(({ sessionId }: { sessionId: string }) => { switchMap(({ sessionId }) => {
return this.stripeService.redirectToCheckout({ 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() { public onCheckout() {
this.dataService this.dataService
.createCheckoutSession({ couponId: this.couponId, priceId: this.priceId }) .createStripeCheckoutSession({
couponId: this.couponId,
priceId: this.priceId
})
.pipe( .pipe(
switchMap(({ sessionId }: { sessionId: string }) => { switchMap(({ sessionId }) => {
return this.stripeService.redirectToCheckout({ sessionId }); return this.stripeService.redirectToCheckout({ sessionId });
}), }),
catchError((error) => { catchError((error) => {

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

@ -32,6 +32,7 @@ import {
AssetProfileIdentifier, AssetProfileIdentifier,
BenchmarkMarketDataDetailsResponse, BenchmarkMarketDataDetailsResponse,
BenchmarkResponse, BenchmarkResponse,
CreateStripeCheckoutSessionResponse,
DataProviderHealthResponse, DataProviderHealthResponse,
Export, Export,
Filter, Filter,
@ -169,17 +170,20 @@ export class DataService {
return params; return params;
} }
public createCheckoutSession({ public createStripeCheckoutSession({
couponId, couponId,
priceId priceId
}: { }: {
couponId?: string; couponId?: string;
priceId: string; priceId: string;
}) { }) {
return this.http.post('/api/v1/subscription/stripe/checkout-session', { return this.http.post<CreateStripeCheckoutSessionResponse>(
'/api/v1/subscription/stripe/checkout-session',
{
couponId, couponId,
priceId priceId
}); }
);
} }
public fetchAccount(aAccountId: string) { 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 { ApiKeyResponse } from './responses/api-key-response.interface';
import type { BenchmarkMarketDataDetailsResponse } from './responses/benchmark-market-data-details-response.interface'; import type { BenchmarkMarketDataDetailsResponse } from './responses/benchmark-market-data-details-response.interface';
import type { BenchmarkResponse } from './responses/benchmark-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 { DataEnhancerHealthResponse } from './responses/data-enhancer-health-response.interface';
import type { DataProviderGhostfolioAssetProfileResponse } from './responses/data-provider-ghostfolio-asset-profile-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'; import type { DataProviderGhostfolioStatusResponse } from './responses/data-provider-ghostfolio-status-response.interface';
@ -95,6 +96,7 @@ export {
BenchmarkProperty, BenchmarkProperty,
BenchmarkResponse, BenchmarkResponse,
Coupon, Coupon,
CreateStripeCheckoutSessionResponse,
DataEnhancerHealthResponse, DataEnhancerHealthResponse,
DataProviderGhostfolioAssetProfileResponse, DataProviderGhostfolioAssetProfileResponse,
DataProviderGhostfolioStatusResponse, DataProviderGhostfolioStatusResponse,

Loading…
Cancel
Save