aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-07 10:39:09 +0200
committerChocobozzz <me@florianbigard.com>2020-05-07 10:39:09 +0200
commit3cc665f48fd233d09f778d7e887488dde6f03ef6 (patch)
treeba8503723206ef17f4b8e4a2e40125472b28dbaf /server/models
parentee8e602ef9761b4869e14d4d3ed24a2e18f22c65 (diff)
downloadPeerTube-3cc665f48fd233d09f778d7e887488dde6f03ef6.tar.gz
PeerTube-3cc665f48fd233d09f778d7e887488dde6f03ef6.tar.zst
PeerTube-3cc665f48fd233d09f778d7e887488dde6f03ef6.zip
Add last login date to users
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/user.ts29
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) {