Skip to content

Commit

Permalink
fix(sanitize,search): sanitize search and convert dash (-) to space
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Dec 16, 2024
1 parent 5f5dc03 commit 07b73b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/lib/server/db/employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export async function getEmployees(
}

// Don't search if the search query is empty when trimmed
const nonEmptySearchQuery = searchQuery
? searchQuery.trim() !== ''
? searchQuery
const sanitizedSearchQuery = searchQuery ? sanitizeString(searchQuery) : undefined;
const nonEmptySearchQuery = sanitizedSearchQuery
? sanitizedSearchQuery !== ''
? sanitizedSearchQuery
: undefined
: undefined;

Expand Down Expand Up @@ -61,7 +62,8 @@ export async function getEmployees(
)
)
.groupBy(employee.id, employee.fname, employee.lname)
.limit(limit);
.limit(limit)
.offset(offset);

return employees.map((s) => {
return {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/server/db/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export async function getStudents(
}

// Don't search if the search query is empty when trimmed
const nonEmptySearchQuery = searchQuery
? searchQuery.trim() !== ''
? searchQuery
const sanitizedSearchQuery = searchQuery ? sanitizeString(searchQuery) : undefined;
const nonEmptySearchQuery = sanitizedSearchQuery
? sanitizedSearchQuery !== ''
? sanitizedSearchQuery
: undefined
: undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/sanitize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function sanitizeString(value: string): string {
return value.trim().toLowerCase().toWellFormed();
return value.trim().toLowerCase().replaceAll('-', ' ').toWellFormed();
}

export function capitalizeString(value: string): string {
Expand Down

0 comments on commit 07b73b8

Please sign in to comment.