MCPcopy Create free account
hub / github.com/TheOrcDev/orcish-fullstack-admin / getUsers

Function getUsers

server/users.ts:19–57  ·  view source on GitHub ↗
(
  input: GetUsersInput
)

Source from the content-addressed store, hash-verified

17}
18
19export async function getUsers(
20 input: GetUsersInput
21): Promise<GetUsersResponse> {
22 try {
23 const offset = (input.page - 1) * input.totalItems;
24 const limit = input.totalItems;
25
26 const [totalCount] = await db
27 .select({ count: count() })
28 .from(users)
29 .where(
30 or(
31 input.search ? ilike(users.email, `%${input.search}%`) : undefined,
32 input.search ? ilike(users.username, `%${input.search}%`) : undefined
33 )
34 );
35
36 const totalPages = Math.ceil(totalCount.count / limit);
37
38 const items = await db
39 .select()
40 .from(users)
41 .where(
42 or(
43 input.search ? ilike(users.email, `%${input.search}%`) : undefined,
44 input.search ? ilike(users.username, `%${input.search}%`) : undefined
45 )
46 )
47 .offset(offset)
48 .limit(limit);
49
50 return {
51 items,
52 totalPages,
53 };
54 } catch (e) {
55 throw e;
56 }
57}
58
59interface CreateUserInput {
60 username: string;

Callers 1

fetchUsersFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected