Fix search
This commit is contained in:
parent
d59e6e11d5
commit
901277bd5b
@ -546,8 +546,12 @@ class Server extends EventEmitter
|
|||||||
if (this.#server)
|
if (this.#server)
|
||||||
{
|
{
|
||||||
this.#logger.info('Closing server');
|
this.#logger.info('Closing server');
|
||||||
|
let closing = false;
|
||||||
const cleanUp = async () =>
|
const cleanUp = async () =>
|
||||||
{
|
{
|
||||||
|
if (closing)
|
||||||
|
return;
|
||||||
|
closing = true;
|
||||||
await this.#mongodb.close();
|
await this.#mongodb.close();
|
||||||
await this.#mariadb?.close();
|
await this.#mariadb?.close();
|
||||||
await this.#memoryStoreProvider.close();
|
await this.#memoryStoreProvider.close();
|
||||||
@ -566,9 +570,8 @@ class Server extends EventEmitter
|
|||||||
});
|
});
|
||||||
setTimeout(() =>
|
setTimeout(() =>
|
||||||
{
|
{
|
||||||
this.#logger.warn('Server close timed out, cleaning up and exiting');
|
this.#logger.warn('Server close timed out, forcefully closing connections');
|
||||||
this.#server?.closeAllConnections();
|
this.#server?.closeAllConnections();
|
||||||
cleanUp();
|
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class UserDatabase implements UserDatabaseInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchUsers ({ ids, page, pageSize, name, roleId, id }: UserQuery = {}): Promise<User[]>
|
async fetchUsers ({ ids, page, pageSize, name, roleId, id, partialName }: UserQuery = {}): Promise<User[]>
|
||||||
{
|
{
|
||||||
const query: Filter<UserData> = {};
|
const query: Filter<UserData> = {};
|
||||||
|
|
||||||
@ -162,7 +162,12 @@ class UserDatabase implements UserDatabaseInterface
|
|||||||
|
|
||||||
// Does not scale, but works for our users collection since it should always remain relatively small
|
// Does not scale, but works for our users collection since it should always remain relatively small
|
||||||
if (name)
|
if (name)
|
||||||
query.name = { $regex: `^${name}$`, $options: 'i' };
|
{
|
||||||
|
if (partialName)
|
||||||
|
query.name = { $regex: name };
|
||||||
|
else
|
||||||
|
query.name = { $regex: `^${name}$`, $options: 'i' };
|
||||||
|
}
|
||||||
|
|
||||||
const findOptions: {limit?: number, skip?: number} = {};
|
const findOptions: {limit?: number, skip?: number} = {};
|
||||||
if (typeof page !== 'undefined' && typeof pageSize !== 'undefined')
|
if (typeof page !== 'undefined' && typeof pageSize !== 'undefined')
|
||||||
|
@ -60,7 +60,7 @@ class UsersEndpoint extends ApiEndpoint
|
|||||||
if (page < 0)
|
if (page < 0)
|
||||||
page = 0;
|
page = 0;
|
||||||
|
|
||||||
const users = await this.#users.fetchUsers({ page, pageSize, name });
|
const users = await this.#users.fetchUsers({ page, pageSize, name, partialName: true });
|
||||||
res.json({
|
res.json({
|
||||||
users: users.map(user => user.json),
|
users: users.map(user => user.json),
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
|
@ -8,7 +8,8 @@ export type Query<T, TData> = {
|
|||||||
ids?: (string | T | TData)[],
|
ids?: (string | T | TData)[],
|
||||||
page?: number,
|
page?: number,
|
||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
name?: string | null
|
name?: string | null,
|
||||||
|
partialName?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RoleQuery = Query<Role, RoleData>
|
export type RoleQuery = Query<Role, RoleData>
|
||||||
|
Loading…
Reference in New Issue
Block a user