diff --git a/CHANGELOG.md b/CHANGELOG.md index 409250551..627a7d7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added the price to the `Subscription` database schema + ### Changed - Changed the execution time of the asset profile data gathering to every Sunday at lunch time - Improved the activities import by providing asset profile details +- Upgraded `@codewithdan/observable-store` from version `2.2.11` to `2.2.15` - Upgraded `bull` from version `4.8.5` to `4.10.2` +- Upgraded `countup.js` from version `2.0.7` to `2.3.2` +- Upgraded the _Internet Identity_ dependencies from version `0.12.1` to `0.15.1` +- Upgraded `prisma` from version `4.7.1` to `4.8.0` ## 1.221.0 - 2022-12-26 diff --git a/apps/api/src/app/.gitkeep b/apps/api/src/app/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index f9eab7018..810611375 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -8,7 +8,6 @@ import { TagService } from '@ghostfolio/api/services/tag/tag.service'; import { DEMO_USER_ID, PROPERTY_IS_READ_ONLY_MODE, - PROPERTY_IS_USER_SIGNUP_ENABLED, PROPERTY_SLACK_COMMUNITY_USERS, PROPERTY_STRIPE_CONFIG, PROPERTY_SYSTEM_MESSAGE, @@ -303,14 +302,14 @@ export class InfoService { return undefined; } - const stripeConfig = await this.prismaService.property.findUnique({ + let subscriptions: Subscription[] = []; + + const stripeConfig = (await this.prismaService.property.findUnique({ where: { key: PROPERTY_STRIPE_CONFIG } - }); + })) ?? { value: '{}' }; - if (stripeConfig) { - return [JSON.parse(stripeConfig.value)]; - } + subscriptions = [JSON.parse(stripeConfig.value)]; - return []; + return subscriptions; } } diff --git a/apps/api/src/app/subscription/subscription.controller.ts b/apps/api/src/app/subscription/subscription.controller.ts index eee815652..4b21482ae 100644 --- a/apps/api/src/app/subscription/subscription.controller.ts +++ b/apps/api/src/app/subscription/subscription.controller.ts @@ -63,6 +63,7 @@ export class SubscriptionController { await this.subscriptionService.createSubscription({ duration: coupon.duration, + price: 0, userId: this.request.user.id }); diff --git a/apps/api/src/app/subscription/subscription.service.ts b/apps/api/src/app/subscription/subscription.service.ts index fa061f369..d3e9dcc7b 100644 --- a/apps/api/src/app/subscription/subscription.service.ts +++ b/apps/api/src/app/subscription/subscription.service.ts @@ -1,6 +1,10 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; -import { DEFAULT_LANGUAGE_CODE } from '@ghostfolio/common/config'; +import { + DEFAULT_LANGUAGE_CODE, + PROPERTY_STRIPE_CONFIG +} from '@ghostfolio/common/config'; +import { Subscription as SubscriptionInterface } from '@ghostfolio/common/interfaces/subscription.interface'; import { SubscriptionType } from '@ghostfolio/common/types/subscription.type'; import { Injectable, Logger } from '@nestjs/common'; import { Subscription } from '@prisma/client'; @@ -70,13 +74,16 @@ export class SubscriptionService { public async createSubscription({ duration = '1 year', + price, userId }: { duration?: StringValue; + price: number; userId: string; }) { await this.prismaService.subscription.create({ data: { + price, expiresAt: addMilliseconds(new Date(), ms(duration)), User: { connect: { @@ -93,7 +100,21 @@ export class SubscriptionService { aCheckoutSessionId ); - await this.createSubscription({ userId: session.client_reference_id }); + let subscriptions: SubscriptionInterface[] = []; + + const stripeConfig = (await this.prismaService.property.findUnique({ + where: { key: PROPERTY_STRIPE_CONFIG } + })) ?? { value: '{}' }; + + subscriptions = [JSON.parse(stripeConfig.value)]; + + const coupon = subscriptions[0]?.coupon ?? 0; + const price = subscriptions[0]?.price ?? 0; + + await this.createSubscription({ + price: price - coupon, + userId: session.client_reference_id + }); await this.stripe.customers.update(session.customer as string, { description: session.client_reference_id diff --git a/apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html b/apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html index 31f48b4d5..982adf896 100644 --- a/apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html +++ b/apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html @@ -19,7 +19,7 @@