Skip to content

Commit fd0577b

Browse files
committed
fix: remove formatSearch in favor of helper-fns
1 parent 6b954f7 commit fd0577b

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/common/database/base.repository.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import { EntityRepository } from "@mikro-orm/postgresql";
1111
import { BadRequestException, NotFoundException } from "@nestjs/common";
1212
import type { Observable } from "rxjs";
1313
import { from, map, of, switchMap, throwError } from "rxjs";
14+
import { formatSearch } from "helper-fns";
1415
import type { BaseEntity } from "./base.entity";
1516

16-
import { translate } from "@lib/i18n";
17-
import { HelperService } from "@common/helpers";
1817
import type {
1918
CursorPaginationResponse,
2019
OppositeOrder,
@@ -31,6 +30,7 @@ import {
3130
getOppositeOrder,
3231
getQueryOrder,
3332
} from "@common/@types";
33+
import { translate } from "@lib/i18n";
3434

3535
export class BaseRepository<T extends BaseEntity> extends EntityRepository<T> {
3636
private readonly encoding: BufferEncoding = "base64";
@@ -291,7 +291,7 @@ export class BaseRepository<T extends BaseEntity> extends EntityRepository<T> {
291291
if (search) {
292292
qb.andWhere({
293293
[searchField]: {
294-
$ilike: HelperService.formatSearch(search),
294+
$ilike: formatSearch(search),
295295
},
296296
});
297297
}
@@ -366,7 +366,7 @@ export class BaseRepository<T extends BaseEntity> extends EntityRepository<T> {
366366
if (search && searchField) {
367367
qb.andWhere({
368368
[searchField]: {
369-
$ilike: HelperService.formatSearch(search),
369+
$ilike: formatSearch(search),
370370
},
371371
});
372372
}

src/common/helpers/helpers.utils.ts

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ directory of the module. */
6060
return process.env.NODE_ENV === "prod" ? join(currentDirectory, "dist") : currentDirectory;
6161
},
6262

63-
/* The `formatSearch` function is used to format a search string for use in a database query. */
64-
formatSearch(search: string): string {
65-
return `%${search.trim().replaceAll("\n", " ").replaceAll(/\s\s+/g, " ").toLowerCase()}%`;
66-
},
6763

6864
/* The `hashString` function is used to hash a user's password using the Argon2 algorithm. It takes a
6965
user's password as input and returns a promise that resolves to the hashed password as a string. The

0 commit comments

Comments
 (0)