Improved the performance of the MasterCorporate

This commit is contained in:
Tiago Ribeiro
2024-09-07 17:34:41 +01:00
parent 56f374bbfe
commit 3be0d158e3
11 changed files with 1197 additions and 1134 deletions

View File

@@ -44,7 +44,15 @@ export async function getSpecificUsers(ids: string[]) {
.toArray();
}
export async function getLinkedUsers(userID?: string, userType?: Type, type?: Type, page?: number, size?: number) {
export async function getLinkedUsers(
userID?: string,
userType?: Type,
type?: Type,
page?: number,
size?: number,
sort?: string,
direction?: "asc" | "desc",
) {
const filters = {
...(!!type ? {type} : {}),
};
@@ -53,6 +61,7 @@ export async function getLinkedUsers(userID?: string, userType?: Type, type?: Ty
const users = await db
.collection("users")
.find<User>(filters)
.sort(sort ? {[sort]: direction === "desc" ? -1 : 1} : {})
.skip(page && size ? page * size : 0)
.limit(size || 0)
.toArray();