Exclude revoked invites in dashboard invite count
This commit is contained in:
parent
c673872548
commit
922fa34302
|
@ -161,6 +161,9 @@ type InvitesService interface {
|
|||
// Count returns the total number of invites.
|
||||
Count(context.Context) (uint, error)
|
||||
|
||||
// CountActive returns the total number of active invites.
|
||||
CountActive(context.Context) (uint, error)
|
||||
|
||||
// Revoke removes a active invite and invalidates it for future use.
|
||||
Revoke(ctx context.Context, id int64) error
|
||||
}
|
||||
|
|
|
@ -258,6 +258,16 @@ func (i Invites) Count(ctx context.Context) (uint, error) {
|
|||
return uint(count), nil
|
||||
}
|
||||
|
||||
func (i Invites) CountActive(ctx context.Context) (uint, error) {
|
||||
count, err := models.Invites(
|
||||
qm.Where("active = true"),
|
||||
).Count(ctx, i.db)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint(count), nil
|
||||
}
|
||||
|
||||
// Revoke removes a active invite and invalidates it for future use.
|
||||
func (i Invites) Revoke(ctx context.Context, id int64) error {
|
||||
return transact(i.db, func(tx *sql.Tx) error {
|
||||
|
|
|
@ -77,9 +77,9 @@ func (h dashboardHandler) overview(w http.ResponseWriter, req *http.Request) (in
|
|||
return nil, fmt.Errorf("failed to count members: %w", err)
|
||||
}
|
||||
|
||||
inviteCount, err := h.dbs.Invites.Count(ctx)
|
||||
inviteCount, err := h.dbs.Invites.CountActive(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to count invites: %w", err)
|
||||
return nil, fmt.Errorf("failed to count active invites: %w", err)
|
||||
}
|
||||
|
||||
deniedCount, err := h.dbs.DeniedKeys.Count(ctx)
|
||||
|
|
Loading…
Reference in New Issue