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:
parent
8fc2032bfa
commit
e039cdc85c
@ -281,6 +281,19 @@ class UserStore implements IUserStore {
|
|||||||
.then((res) => Number(res[0].count));
|
.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 {}
|
destroy(): void {}
|
||||||
|
|
||||||
async exists(id: number): Promise<boolean> {
|
async exists(id: number): Promise<boolean> {
|
||||||
|
@ -38,5 +38,6 @@ export interface IUserStore extends Store<IUser, number> {
|
|||||||
incLoginAttempts(user: IUser): Promise<void>;
|
incLoginAttempts(user: IUser): Promise<void>;
|
||||||
successfullyLogin(user: IUser): Promise<number>;
|
successfullyLogin(user: IUser): Promise<number>;
|
||||||
count(): Promise<number>;
|
count(): Promise<number>;
|
||||||
|
countRecentlyDeleted(): Promise<number>;
|
||||||
countServiceAccounts(): Promise<number>;
|
countServiceAccounts(): Promise<number>;
|
||||||
}
|
}
|
||||||
|
@ -192,4 +192,7 @@ test('should delete user', async () => {
|
|||||||
await expect(() => stores.userStore.get(user.id)).rejects.toThrow(
|
await expect(() => stores.userStore.get(user.id)).rejects.toThrow(
|
||||||
new NotFoundError('No user found'),
|
new NotFoundError('No user found'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const deletedCount = await stores.userStore.countRecentlyDeleted();
|
||||||
|
expect(deletedCount).toBe(1);
|
||||||
});
|
});
|
||||||
|
4
src/test/fixtures/fake-user-store.ts
vendored
4
src/test/fixtures/fake-user-store.ts
vendored
@ -67,6 +67,10 @@ class UserStoreMock implements IUserStore {
|
|||||||
return this.data.length;
|
return this.data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async countRecentlyDeleted(): Promise<number> {
|
||||||
|
return Promise.resolve(0);
|
||||||
|
}
|
||||||
|
|
||||||
async get(key: number): Promise<IUser> {
|
async get(key: number): Promise<IUser> {
|
||||||
return this.data.find((u) => u.id === key)!;
|
return this.data.find((u) => u.id === key)!;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user