1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: count recently deleted users (#8688)

This commit is contained in:
Mateusz Kwasniewski 2024-11-07 11:57:47 +01:00 committed by GitHub
parent 8fc2032bfa
commit e039cdc85c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 0 deletions

View File

@ -281,6 +281,19 @@ class UserStore implements IUserStore {
.then((res) => Number(res[0].count));
}
async countRecentlyDeleted(): Promise<number> {
return this.db(TABLE)
.whereNotNull('deleted_at')
.andWhere(
'deleted_at',
'>=',
this.db.raw(`NOW() - INTERVAL '1 month'`),
)
.andWhere({ is_service: false, is_system: false })
.count('*')
.then((res) => Number(res[0].count));
}
destroy(): void {}
async exists(id: number): Promise<boolean> {

View File

@ -38,5 +38,6 @@ export interface IUserStore extends Store<IUser, number> {
incLoginAttempts(user: IUser): Promise<void>;
successfullyLogin(user: IUser): Promise<number>;
count(): Promise<number>;
countRecentlyDeleted(): Promise<number>;
countServiceAccounts(): Promise<number>;
}

View File

@ -192,4 +192,7 @@ test('should delete user', async () => {
await expect(() => stores.userStore.get(user.id)).rejects.toThrow(
new NotFoundError('No user found'),
);
const deletedCount = await stores.userStore.countRecentlyDeleted();
expect(deletedCount).toBe(1);
});

View File

@ -67,6 +67,10 @@ class UserStoreMock implements IUserStore {
return this.data.length;
}
async countRecentlyDeleted(): Promise<number> {
return Promise.resolve(0);
}
async get(key: number): Promise<IUser> {
return this.data.find((u) => u.id === key)!;
}