Browse Source

Bugfix/daily requests check in Ghostfolio data provider (#7485)

Fix daily requests check
pull/7493/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
0a01d4234a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.controller.ts
  2. 8
      apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts
  3. 2
      apps/api/src/app/user/user.service.ts

12
apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.controller.ts

@ -51,7 +51,7 @@ export class GhostfolioController {
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests(); const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
if ( if (
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests this.request.user.dataProviderGhostfolioDailyRequests >= maxDailyRequests
) { ) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
@ -95,7 +95,7 @@ export class GhostfolioController {
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests(); const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
if ( if (
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests this.request.user.dataProviderGhostfolioDailyRequests >= maxDailyRequests
) { ) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
@ -135,7 +135,7 @@ export class GhostfolioController {
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests(); const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
if ( if (
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests this.request.user.dataProviderGhostfolioDailyRequests >= maxDailyRequests
) { ) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
@ -176,7 +176,7 @@ export class GhostfolioController {
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests(); const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
if ( if (
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests this.request.user.dataProviderGhostfolioDailyRequests >= maxDailyRequests
) { ) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
@ -215,7 +215,7 @@ export class GhostfolioController {
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests(); const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
if ( if (
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests this.request.user.dataProviderGhostfolioDailyRequests >= maxDailyRequests
) { ) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
@ -252,7 +252,7 @@ export class GhostfolioController {
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests(); const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
if ( if (
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests this.request.user.dataProviderGhostfolioDailyRequests >= maxDailyRequests
) { ) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS), getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),

8
apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts

@ -326,8 +326,12 @@ export class GhostfolioService {
} }
public async incrementDailyRequests({ userId }: { userId: string }) { public async incrementDailyRequests({ userId }: { userId: string }) {
await this.prismaService.analytics.update({ await this.prismaService.analytics.upsert({
data: { create: {
dataProviderGhostfolioDailyRequests: 1,
user: { connect: { id: userId } }
},
update: {
dataProviderGhostfolioDailyRequests: { increment: 1 } dataProviderGhostfolioDailyRequests: { increment: 1 }
}, },
where: { userId } where: { userId }

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

@ -326,7 +326,7 @@ export class UserService {
updatedAt, updatedAt,
activityCount: analytics?.activityCount, activityCount: analytics?.activityCount,
dataProviderGhostfolioDailyRequests: dataProviderGhostfolioDailyRequests:
analytics?.dataProviderGhostfolioDailyRequests analytics?.dataProviderGhostfolioDailyRequests ?? 0
}; };
if (user.settings) { if (user.settings) {

Loading…
Cancel
Save