Browse Source

Feature/add lastRequestAt to analytics (#4010)

* Add lastRequestAt to Analytics
pull/4011/head
Thomas Kaul 3 months ago
committed by GitHub
parent
commit
a80ca507f8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      apps/api/src/app/admin/admin.service.ts
  2. 2
      apps/api/src/app/auth/jwt.strategy.ts
  3. 2
      apps/api/src/app/info/info.service.ts
  4. 5
      prisma/migrations/20241102121004_added_last_request_at_to_analytics/migration.sql
  5. 2
      prisma/schema.prisma

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

@ -641,7 +641,7 @@ export class AdminService {
}
private async getUsersWithAnalytics(): Promise<AdminUsers['users']> {
let orderBy: any = {
let orderBy: Prisma.UserOrderByWithRelationInput = {
createdAt: 'desc'
};
let where: Prisma.UserWhereInput;
@ -649,7 +649,7 @@ export class AdminService {
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
orderBy = {
Analytics: {
updatedAt: 'desc'
lastRequestAt: 'desc'
}
};
where = {

2
apps/api/src/app/auth/jwt.strategy.ts

@ -46,7 +46,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
update: {
country,
activityCount: { increment: 1 },
updatedAt: new Date()
lastRequestAt: new Date()
},
where: { userId: user.id }
});

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

@ -142,7 +142,7 @@ export class InfoService {
},
{
Analytics: {
updatedAt: {
lastRequestAt: {
gt: subDays(new Date(), aDays)
}
}

5
prisma/migrations/20241102121004_added_last_request_at_to_analytics/migration.sql

@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Analytics" ADD COLUMN "lastRequestAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- CreateIndex
CREATE INDEX "Analytics_lastRequestAt_idx" ON "Analytics"("lastRequestAt");

2
prisma/schema.prisma

@ -68,10 +68,12 @@ model Analytics {
activityCount Int @default(0)
country String?
dataProviderGhostfolioDailyRequests Int @default(0)
lastRequestAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String @id
User User @relation(fields: [userId], onDelete: Cascade, references: [id])
@@index([lastRequestAt])
@@index([updatedAt])
}

Loading…
Cancel
Save