Skip to content

Commit

Permalink
TRELLO-2204: fix department filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ssedoudbgouv committed Feb 22, 2024
1 parent 4a73471 commit 42ebfd6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/repositories/company/CompanyRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import repositories.CRUDRepository
import slick.basic.DatabaseConfig
import utils.Constants.ActionEvent.POST_FOLLOW_UP_DOC
import utils.Constants.ActionEvent.REPORT_CLOSED_BY_NO_READING
import utils.Constants.Departments.toPostalCode

import java.sql.Timestamp
import java.time.OffsetDateTime
Expand Down Expand Up @@ -53,8 +54,17 @@ 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, _) =>
// 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}%")
.reduceLeft(_ || _)
// Avoid searching departments in foreign countries
departmentsFilter && report.map(_.companyCountry).isEmpty

}
.filterIf(search.activityCodes.nonEmpty) { case (company, _) =>
company.activityCode.map(a => a.inSet(search.activityCodes)).getOrElse(false)
Expand Down

0 comments on commit 42ebfd6

Please sign in to comment.