const customers = await ctx.db.query.customers.findMany({
where: (customers, ops) =>
ops.and(
ops.eq(customers.organizationId, ctx.session.user.organization.id),
input?.query
? ops.or(
ops.like(customers.displayName, input.query),
ops.sql`${customers.firstName} + " " + ${customers.lastName} LIKE '%${input.query}%'`
)
: undefined,
input?.categoryId
? ops.eq(customers.categoryId, input.categoryId)
: undefined
),
});
return customers;
const customers = await ctx.db.query.customers.findMany({
where: (customers, ops) =>
ops.and(
ops.eq(customers.organizationId, ctx.session.user.organization.id),
input?.query
? ops.or(
ops.like(customers.displayName, input.query),
ops.sql`${customers.firstName} + " " + ${customers.lastName} LIKE '%${input.query}%'`
)
: undefined,
input?.categoryId
? ops.eq(customers.categoryId, input.categoryId)
: undefined
),
});
return customers;