Skip to content

Commit

Permalink
fix roles stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
OSousa117 committed Oct 30, 2023
1 parent debce57 commit 5fe538c
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ public void calculateTodos(String userID) {
userRepository
.findById(UUID.fromString(userID))
.ifPresent(
user -> {
List<MaterialDemandEntity> demands = fetchDemandsBasedOnRole(user, userID);
user -> {
List<MaterialDemandEntity> demands = fetchDemandsBasedOnRole(user, userID);

StatusesEntity statusesEntity = statusesRepository
.findByUserID(UUID.fromString(userID))
.orElseGet(() -> generateNewEntity(userID));

statusesEntity.setTodosCount(demands.size());
statusesRepository.save(statusesEntity);
}
}
);
}

Expand All @@ -77,13 +77,13 @@ private StatusesEntity generateNewEntity(String userID) {
private List<MaterialDemandEntity> fetchDemandsBasedOnRole(UserEntity user, String userID) {
List<MaterialDemandEntity> demands = new ArrayList<>();

if (user.getRole().equals(Role.CUSTOMER)) {
demands = materialDemandRepository.findByCustomerId_Id(UUID.fromString(userID))
if (user.getRole().equals(Role.SUPPLIER)) {
demands = materialDemandRepository.findAll() //TODO SUPPLIER AQUI findbysupplierID
.stream()
.filter(d -> d.getDemandSeries().stream().allMatch(series -> series.getDemandSeriesValues().stream().allMatch(value -> value.getDemand() == 0)))
.collect(Collectors.toList());
} else if (user.getRole().equals(Role.SUPPLIER)) {
demands = materialDemandRepository.findBySupplierId_Id(UUID.fromString(userID))
} else if (user.getRole().equals(Role.CUSTOMER)) {
demands = materialDemandRepository.findAll() //TODO CUSTOMER AQUI findbycustomerID
.stream()
.filter(d -> d.getLinkStatus() == EventType.UN_LINKED)
.collect(Collectors.toList());
Expand Down

0 comments on commit 5fe538c

Please sign in to comment.