diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/user.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 260c1b28e..fbd3080c6 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -353,6 +353,11 @@ export class UserModel extends Model<UserModel> { | |||
353 | @Column | 353 | @Column |
354 | pluginAuth: string | 354 | pluginAuth: string |
355 | 355 | ||
356 | @AllowNull(true) | ||
357 | @Default(null) | ||
358 | @Column | ||
359 | lastLoginDate: Date | ||
360 | |||
356 | @CreatedAt | 361 | @CreatedAt |
357 | createdAt: Date | 362 | createdAt: Date |
358 | 363 | ||
@@ -691,10 +696,28 @@ export class UserModel extends Model<UserModel> { | |||
691 | } | 696 | } |
692 | 697 | ||
693 | static async getStats () { | 698 | static async getStats () { |
699 | function getActiveUsers (days: number) { | ||
700 | const query = { | ||
701 | where: { | ||
702 | [Op.and]: [ | ||
703 | literal(`"lastLoginDate" > NOW() - INTERVAL '${days}d'`) | ||
704 | ] | ||
705 | } | ||
706 | } | ||
707 | |||
708 | return UserModel.count(query) | ||
709 | } | ||
710 | |||
694 | const totalUsers = await UserModel.count() | 711 | const totalUsers = await UserModel.count() |
712 | const totalDailyActiveUsers = await getActiveUsers(1) | ||
713 | const totalWeeklyActiveUsers = await getActiveUsers(7) | ||
714 | const totalMonthlyActiveUsers = await getActiveUsers(30) | ||
695 | 715 | ||
696 | return { | 716 | return { |
697 | totalUsers | 717 | totalUsers, |
718 | totalDailyActiveUsers, | ||
719 | totalWeeklyActiveUsers, | ||
720 | totalMonthlyActiveUsers | ||
698 | } | 721 | } |
699 | } | 722 | } |
700 | 723 | ||
@@ -808,7 +831,9 @@ export class UserModel extends Model<UserModel> { | |||
808 | 831 | ||
809 | createdAt: this.createdAt, | 832 | createdAt: this.createdAt, |
810 | 833 | ||
811 | pluginAuth: this.pluginAuth | 834 | pluginAuth: this.pluginAuth, |
835 | |||
836 | lastLoginDate: this.lastLoginDate | ||
812 | } | 837 | } |
813 | 838 | ||
814 | if (parameters.withAdminFlags) { | 839 | if (parameters.withAdminFlags) { |