Skip to content

Commit

Permalink
feat(users): allow search on family and given name too (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil authored Oct 15, 2024
1 parent 061ba55 commit 4be0653
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/~/users/api/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import type { App_Context } from "@~/app.middleware/context";
import type { urls } from "@~/app.urls";
import { schema, type MonComptePro_PgDatabase } from "@~/moncomptepro.database";
import { and, desc, count as drizzle_count, ilike } from "drizzle-orm";
import { desc, count as drizzle_count, ilike, or } from "drizzle-orm";
import type { Env, InferRequestType } from "hono";
import { useRequestContext } from "hono/jsx-renderer";

Expand Down Expand Up @@ -50,7 +50,11 @@ export function get_users_list(
) {
const { page, page_size: take } = pagination;

const where = and(ilike(schema.users.email, `%${search ?? ""}%`));
const where = or(
ilike(schema.users.family_name, `%${search ?? ""}%`),
ilike(schema.users.given_name, `%${search ?? ""}%`),
ilike(schema.users.email, `%${search ?? ""}%`),
);
return pg.transaction(async function users_with_count(tx) {
const users = await tx
.select({
Expand Down

0 comments on commit 4be0653

Please sign in to comment.