misc: added pagination and moved to admin route

This commit is contained in:
Sheen Capadngan
2024-07-09 00:34:07 +08:00
parent f3a8fda254
commit c1b242db67
14 changed files with 276 additions and 177 deletions
+29 -2
View File
@@ -10,7 +10,7 @@ import {
TUserEncryptionKeysUpdate
} from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
import { ormify } from "@app/lib/knex";
import { ormify, selectAllTableCols } from "@app/lib/knex";
export type TUserDALFactory = ReturnType<typeof userDALFactory>;
@@ -18,6 +18,32 @@ export const userDALFactory = (db: TDbClient) => {
const userOrm = ormify(db, TableName.Users);
const findUserByUsername = async (username: string, tx?: Knex) => userOrm.findOne({ username }, tx);
const getUsersByFilter = async ({
limit,
offset,
searchTerm
}: {
limit: number;
offset: number;
searchTerm: string;
}) => {
try {
let query = db.replicaNode()(TableName.Users).where("isGhost", "=", false);
if (searchTerm) {
query = query.where((qb) => {
void qb
.whereILike("email", `%${searchTerm}%`)
.orWhereILike("firstName", `%${searchTerm}%`)
.orWhereILike("lastName", `%${searchTerm}%`)
.orWhereLike("username", `%${searchTerm}%`);
});
}
return await query.limit(limit).offset(offset).select(selectAllTableCols(TableName.Users));
} catch (error) {
throw new DatabaseError({ error, name: "Get users by filter" });
}
};
// USER ENCRYPTION FUNCTIONS
// -------------------------
const findUserEncKeyByUsername = async ({ username }: { username: string }) => {
@@ -159,6 +185,7 @@ export const userDALFactory = (db: TDbClient) => {
upsertUserEncryptionKey,
createUserEncryption,
findOneUserAction,
createUserAction
createUserAction,
getUsersByFilter
};
};
+1 -6
View File
@@ -295,10 +295,6 @@ export const userServiceFactory = ({
return updatedOrgMembership.projectFavorites;
};
const listUsers = async () => {
return userDAL.find({});
};
return {
sendEmailVerificationCode,
verifyEmailVerificationCode,
@@ -312,7 +308,6 @@ export const userServiceFactory = ({
unlockUser,
getUserPrivateKey,
getUserProjectFavorites,
updateUserProjectFavorites,
listUsers
updateUserProjectFavorites
};
};