Allow searching events

Also upgrade Fresh
This commit is contained in:
Bruno Bernardino
2024-03-23 16:11:36 +00:00
parent 9cd5d9f43d
commit 5b3217cdfc
8 changed files with 226 additions and 78 deletions

View File

@@ -28,13 +28,13 @@ export async function getContactsCount(userId: string) {
return Number(results[0]?.count || 0);
}
export async function searchContacts(search: string, userId: string, pageIndex: number) {
export async function searchContacts(searchTerm: string, userId: string, pageIndex: number) {
const contacts = await db.query<Pick<Contact, 'id' | 'first_name' | 'last_name'>>(
sql`SELECT "id", "first_name", "last_name" FROM "bewcloud_contacts" WHERE "user_id" = $1 AND ("first_name" ILIKE $3 OR "last_name" ILIKE $3 OR "extra"::text ILIKE $3) ORDER BY "first_name" ASC, "last_name" ASC LIMIT ${CONTACTS_PER_PAGE_COUNT} OFFSET $2`,
[
userId,
pageIndex * CONTACTS_PER_PAGE_COUNT,
`%${search}%`,
`%${searchTerm.split(' ').join('%')}%`,
],
);