Introduce renewal-early-bird (#2982)

pull/2984/head
Thomas Kaul 11 months ago committed by GitHub
parent ccaf06360a
commit ef9d77312e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

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

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

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

Loading…
Cancel
Save