diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java index 687917df..ca266679 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CompanyDocumentDao.java @@ -333,6 +333,11 @@ public class CompanyDocumentDao { predicate = builder.and(predicate, builder.isFalse(root.get("isDeleted"))); + predicate = builder.and( + predicate, + builder.notEqual(root.get("status"), CompanyDocumentStatusEnum.EXPIRED.getValue()) + ); + if (typeEnum != null) { if (typeEnum == CompanyDocumentTypeEnum.COMPANY_DOCUMENT) { // Case 1: Fetch only COMPANY_DOCUMENT type documents for the given company @@ -346,15 +351,15 @@ public class CompanyDocumentDao { builder.equal(root.get("userWithCompany").get("userId"), userId) ); } + }else { + // Case 3: If typeEnum is null, fetch all documents for the company and personal documents for the user + Predicate companyPredicate = builder.equal(root.get("companyId"), companyId); + Predicate personalPredicate = builder.and( + builder.equal(root.get("type"), CompanyDocumentTypeEnum.PERSONAL_DOCUMENT.getValue()), + builder.equal(root.get("userWithCompany").get("userId"), userId) + ); + predicate = builder.and(predicate, builder.or(companyPredicate, personalPredicate)); } - // Case 3: If typeEnum is null, fetch all documents for the company and personal documents for the user - Predicate companyPredicate = builder.equal(root.get("companyId"), companyId); - Predicate personalPredicate = builder.and( - builder.equal(root.get("type"), CompanyDocumentTypeEnum.PERSONAL_DOCUMENT.getValue()), - builder.equal(root.get("userWithCompany").get("userId"), userId) - ); - predicate = builder.and(predicate, builder.or(companyPredicate, personalPredicate)); - predicate = builder.equal(root.get("status"), CompanyDocumentStatusEnum.VALID.getValue()); return predicate; }; }