Browse Source

Introduce renewal-early-bird (#2982)

pull/2984/head
Thomas Kaul 12 months ago
committed by GitHub
parent
commit
ef9d77312e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      apps/api/src/app/admin/admin.service.ts
  2. 25
      apps/api/src/app/subscription/subscription.service.ts
  3. 6
      apps/api/src/app/user/user.service.ts
  4. 2
      libs/common/src/lib/types/subscription-offer.type.ts

5
apps/api/src/app/admin/admin.service.ts

@ -455,7 +455,10 @@ export class AdminService {
const subscription = this.configurationService.get( const subscription = this.configurationService.get(
'ENABLE_FEATURE_SUBSCRIPTION' 'ENABLE_FEATURE_SUBSCRIPTION'
) )
? this.subscriptionService.getSubscription(Subscription) ? this.subscriptionService.getSubscription({
createdAt,
subscriptions: Subscription
})
: undefined; : undefined;
return { return {

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

@ -1,7 +1,8 @@
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config'; import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config';
import { UserWithSettings } from '@ghostfolio/common/types'; import { parseDate } from '@ghostfolio/common/helper';
import { SubscriptionOffer, UserWithSettings } from '@ghostfolio/common/types';
import { SubscriptionType } from '@ghostfolio/common/types/subscription-type.type'; import { SubscriptionType } from '@ghostfolio/common/types/subscription-type.type';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { Subscription } from '@prisma/client'; import { Subscription } from '@prisma/client';
@ -107,17 +108,27 @@ export class SubscriptionService {
} }
} }
public getSubscription( public getSubscription({
aSubscriptions: Subscription[] createdAt,
): UserWithSettings['subscription'] { subscriptions
if (aSubscriptions.length > 0) { }: {
const { expiresAt, price } = aSubscriptions.reduce((a, b) => { createdAt: UserWithSettings['createdAt'];
subscriptions: Subscription[];
}): UserWithSettings['subscription'] {
if (subscriptions.length > 0) {
const { expiresAt, price } = subscriptions.reduce((a, b) => {
return new Date(a.expiresAt) > new Date(b.expiresAt) ? a : b; return new Date(a.expiresAt) > new Date(b.expiresAt) ? a : b;
}); });
let offer: SubscriptionOffer = price ? 'renewal' : 'default';
if (isBefore(createdAt, parseDate('2023-01-01'))) {
offer = 'renewal-early-bird';
}
return { return {
expiresAt, expiresAt,
offer: price ? 'renewal' : 'default', offer,
type: isBefore(new Date(), expiresAt) type: isBefore(new Date(), expiresAt)
? SubscriptionType.Premium ? SubscriptionType.Premium
: SubscriptionType.Basic : SubscriptionType.Basic

6
apps/api/src/app/user/user.service.ts

@ -211,8 +211,10 @@ export class UserService {
} }
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
user.subscription = user.subscription = this.subscriptionService.getSubscription({
this.subscriptionService.getSubscription(Subscription); createdAt: user.createdAt,
subscriptions: Subscription
});
if (user.subscription?.type === 'Basic') { if (user.subscription?.type === 'Basic') {
const daysSinceRegistration = differenceInDays( const daysSinceRegistration = differenceInDays(

2
libs/common/src/lib/types/subscription-offer.type.ts

@ -1 +1 @@
export type SubscriptionOffer = 'default' | 'renewal'; export type SubscriptionOffer = 'default' | 'renewal' | 'renewal-early-bird';

Loading…
Cancel
Save