Skip to content

Commit

Permalink
TRELLO-2224: fix department filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ssedoudbgouv committed Mar 4, 2024
1 parent 22c153b commit 1e02784
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions app/repositories/company/CompanyRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ class CompanyRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(impl
val query = table
.joinLeft(ReportTable.table(Some(userRole)))
.on(_.id === _.companyId)
// .filterIf(search.departments.nonEmpty) { case (company, _) =>
// company.department.map(a => a.inSet(search.departments)).getOrElse(false)
// }
.filterIf(search.departments.nonEmpty) { case (company, report) =>
val departmentsFilter: Rep[Boolean] = search.departments
.flatMap(toPostalCode)
.map(dep => company.department.asColumnOf[String] like s"${dep}%")
.map { dep =>
company.postalCode.asColumnOf[String] like s"${dep}%"
}
.reduceLeft(_ || _)
// Avoid searching departments in foreign countries
departmentsFilter && report.map(_.companyCountry).isEmpty
Expand Down

0 comments on commit 1e02784

Please sign in to comment.