Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
micnori committed Sep 16, 2024
2 parents 72d2f56 + 1b02bf8 commit 0eb039a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface EmployeeRepository extends MongoRepository<Employee, String> {

public List<Employee> findByCampaigns(String campaignId);

public List<Employee> findByCompanyIdAndLocation(String id, String location);
public List<Employee> findByCompanyIdAndLocationIgnoreCase(String id, String location);

public List<Employee> findByCompanyId(String companyId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,18 @@ public CompanyLocation updateLocation(String companyId, CompanyLocation location
* @param companyId
* @param locationId
*/
public void deleteLocation(String companyId, String locationId) {
companyRepo.findById(companyId).ifPresent(company -> {
public void deleteLocation(String companyId, String locationId) throws InconsistentDataException {
Company company = companyRepo.findById(companyId).orElse(null);
if(company != null) {
List<Employee> list = employeeRepo.findByCompanyIdAndLocationIgnoreCase(companyId, locationId);
if(list.size() > 0) {
throw new InconsistentDataException("Location has employees", "INVALID_LOCATION_DATA_EMPLOYEE");
}
if (company.getLocations() != null) {
company.getLocations().removeIf(l -> l.getId() == null && locationId == null || l.getId().equalsIgnoreCase(locationId));
companyRepo.save(company);
}
});
}
}
/**
* @param companyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public List<DayStat> statistics(
} else if (location != null && companyId != null) {
Company company = companyRepo.findById(companyId).orElse(null);
if (company == null) throw new InconsistentDataException("Invalid company: " + companyId, "NO_COMPANY");
Set<String> employeeKeys = employeeRepo.findByCompanyIdAndLocation(companyId, location).stream().map(e -> e.getCode()).collect(Collectors.toSet());
Set<String> employeeKeys = employeeRepo.findByCompanyIdAndLocationIgnoreCase(companyId, location).stream().map(e -> e.getCode()).collect(Collectors.toSet());
List<String> users = userRepo.findByCampaignAndCompanyAndEmployeeCode(campaignId, company.getCode(), employeeKeys).stream().map(u -> u.getPlayerId()).collect(Collectors.toList());
criteria = criteria.and("playerId").in(users);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ public ResponseEntity<CompanyLocation> updateLocation(@PathVariable String compa
* @param companyId
* @param locationId
* @return
* @throws InconsistentDataException
*/
@DeleteMapping("/companies/{companyId}/locations/{locationId:.*}")
//@PreAuthorize("hasAnyAuthority(\"" + Constants.ROLE_ADMIN + "\", \""+Constants.ROLE_COMPANY_ADMIN +"\")")
public ResponseEntity<Void> deleteLocation(@PathVariable String companyId, @PathVariable String locationId) {
public ResponseEntity<Void> deleteLocation(@PathVariable String companyId, @PathVariable String locationId) throws InconsistentDataException {
log.debug("Deleting a location {} / {}", companyId, locationId);
if (!userService.isInCompanyRole(companyId, Constants.ROLE_TERRITORY_MANAGER, Constants.ROLE_MOBILITY_MANAGER)) throw new SecurityException("Insufficient rights");
companyService.deleteLocation(companyId, locationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<p>E’ possibile impostare la posizione della sede manualmente oppure automaticamente in base all’indirizzo inserito.</p>
</div>

<p v-if="!showErrorLocation ">
<p v-if="!showErrorLocation && !addresIsValid ">
Per poter impostare una posizione è necessario indicare l’indirizzo
della sede.
</p>
Expand Down

0 comments on commit 0eb039a

Please sign in to comment.