diff --git a/source/backend/api/Services/CompReqFinancialService.cs b/source/backend/api/Services/CompReqFinancialService.cs index 2eb98406d5..066eb63b81 100644 --- a/source/backend/api/Services/CompReqFinancialService.cs +++ b/source/backend/api/Services/CompReqFinancialService.cs @@ -39,6 +39,15 @@ public IEnumerable GetAllByAcquisitionFileId(long acquisit return _compReqFinancialRepository.GetAllByAcquisitionFileId(acquisitionFileId, finalOnly); } + public IEnumerable GetAllByLeaseFileId(long leaseFileId, bool? finalOnly) + { + _logger.LogInformation("Getting pims comp req financials by {leaseFileId}", leaseFileId); + _user.ThrowIfNotAuthorized(Permissions.CompensationRequisitionView); + _user.ThrowIfNotAuthorized(Permissions.LeaseView); + + return _compReqFinancialRepository.GetAllByLeaseFileId(leaseFileId, finalOnly); + } + public IEnumerable SearchCompensationRequisitionFinancials(AcquisitionReportFilterModel filter) { _logger.LogInformation("Searching all comp req financials matching the filter: {filter}", filter); diff --git a/source/backend/api/Services/CompensationRequisitionService.cs b/source/backend/api/Services/CompensationRequisitionService.cs index 2e6c2ef96f..f54b584a47 100644 --- a/source/backend/api/Services/CompensationRequisitionService.cs +++ b/source/backend/api/Services/CompensationRequisitionService.cs @@ -266,7 +266,10 @@ private PimsCompensationRequisition UpdateLeaseFileCompensation(PimsCompensation var currentCompensation = _compensationRequisitionRepository.GetById(compensationRequisition.CompensationRequisitionId); + var currentLeaseFile = _leaseRepository.Get((long)currentCompensation.LeaseId); + CheckTotalAllowableCompensation(currentLeaseFile, compensationRequisition); compensationRequisition.FinalizedDate = GetFinalizedDate(currentCompensation.IsDraft, compensationRequisition.IsDraft, currentCompensation.FinalizedDate); + PimsCompensationRequisition updatedEntity = _compensationRequisitionRepository.Update(compensationRequisition); AddLeaseNoteIfStatusChanged(compensationRequisition.Internal_Id, (long)compensationRequisition.LeaseId, currentCompensation.IsDraft, compensationRequisition.IsDraft); @@ -344,6 +347,22 @@ private void CheckTotalAllowableCompensation(PimsAcquisitionFile currentAcquisit } } + private void CheckTotalAllowableCompensation(PimsLease currentLeaseFile, PimsCompensationRequisition newCompensation) + { + if (!currentLeaseFile.TotalAllowableCompensation.HasValue || (newCompensation.IsDraft.HasValue && newCompensation.IsDraft.Value)) + { + return; + } + + IEnumerable allFinancialsForFile = _compReqFinancialService.GetAllByLeaseFileId(currentLeaseFile.LeaseId, true); + IEnumerable allUnchangedFinancialsForFile = allFinancialsForFile.Where(f => f.CompensationRequisitionId != newCompensation.CompensationRequisitionId); + decimal newTotalCompensation = allUnchangedFinancialsForFile.Concat(newCompensation.PimsCompReqFinancials).Aggregate(0m, (acc, f) => acc + (f.TotalAmt ?? 0m)); + if (newTotalCompensation > currentLeaseFile.TotalAllowableCompensation) + { + throw new BusinessRuleViolationException("Your compensation requisition cannot be saved in FINAL status, as its compensation amount exceeds total allowable compensation for this file."); + } + } + private AcquisitionStatusTypes GetCurrentAcquisitionStatus(long acquisitionFileId) { var currentAcquisitionFile = _acqFileRepository.GetById(acquisitionFileId); diff --git a/source/backend/api/Services/ICompReqFinancialService.cs b/source/backend/api/Services/ICompReqFinancialService.cs index 5324121471..491be1d805 100644 --- a/source/backend/api/Services/ICompReqFinancialService.cs +++ b/source/backend/api/Services/ICompReqFinancialService.cs @@ -8,6 +8,8 @@ public interface ICompReqFinancialService { IEnumerable GetAllByAcquisitionFileId(long acquisitionFileId, bool? finalOnly); + IEnumerable GetAllByLeaseFileId(long leaseFileId, bool? finalOnly); + IEnumerable SearchCompensationRequisitionFinancials(AcquisitionReportFilterModel filter); } } diff --git a/source/backend/api/Services/LeaseService.cs b/source/backend/api/Services/LeaseService.cs index 61a690dd4c..1761d04ef0 100644 --- a/source/backend/api/Services/LeaseService.cs +++ b/source/backend/api/Services/LeaseService.cs @@ -36,6 +36,7 @@ public class LeaseService : BaseService, ILeaseService private readonly IUserRepository _userRepository; private readonly IPropertyService _propertyService; private readonly ILookupRepository _lookupRepository; + private readonly ICompReqFinancialService _compReqFinancialService; public LeaseService( ClaimsPrincipal user, @@ -52,7 +53,8 @@ public LeaseService( IConsultationRepository consultationRepository, IUserRepository userRepository, IPropertyService propertyService, - ILookupRepository lookupRepository) + ILookupRepository lookupRepository, + ICompReqFinancialService compReqFinancialService) : base(user, logger) { _logger = logger; @@ -69,6 +71,7 @@ public LeaseService( _userRepository = userRepository; _propertyService = propertyService; _lookupRepository = lookupRepository; + _compReqFinancialService = compReqFinancialService; } public PimsLease GetById(long leaseId) @@ -229,6 +232,8 @@ public PimsLease Update(PimsLease lease, IEnumerable userOverr ValidateRenewalDates(lease, lease.PimsLeaseRenewals); + ValidateNewTotalAllowableCompensation(lease.LeaseId, lease.TotalAllowableCompensation); + _leaseRepository.Update(lease, false); var leaseWithProperties = AssociatePropertyLeases(lease, userOverrides); @@ -271,6 +276,7 @@ public PimsLease Update(PimsLease lease, IEnumerable userOverr } _leaseRepository.CommitTransaction(); + return _leaseRepository.GetNoTracking(lease.LeaseId); } @@ -449,6 +455,22 @@ private static void ValidateRenewalDates(PimsLease lease, ICollection allFinalFinancialsOnFile = _compReqFinancialService.GetAllByLeaseFileId(currentLeaseFileId, true); + var currentActualCompensation = allFinalFinancialsOnFile.Aggregate(0m, (acc, f) => acc + (f.TotalAmt ?? 0m)); + if (newAllowableCompensation < currentActualCompensation) + { + throw new BusinessRuleViolationException("The Total Allowable Compensation value cannot be saved because the value provided is less than current sum of the final compensation requisitions in this file. " + + "\n\nTo continue, adjust the value to accommodate the existing compensation requisitions in the file or contact your system administrator to adjust final compensations."); + } + } + private PimsLeaseNote GeneratePimsLeaseNote(PimsLease currentLease, PimsLease lease) { var leaseStatuses = _lookupRepository.GetAllLeaseStatusTypes(); diff --git a/source/backend/apimodels/Models/Concepts/Lease/LeaseMap.cs b/source/backend/apimodels/Models/Concepts/Lease/LeaseMap.cs index 938ce78f35..d5ddd7fb42 100644 --- a/source/backend/apimodels/Models/Concepts/Lease/LeaseMap.cs +++ b/source/backend/apimodels/Models/Concepts/Lease/LeaseMap.cs @@ -53,6 +53,7 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.CancellationReason, src => src.CancellationReason) .Map(dest => dest.TerminationReason, src => src.TerminationReason) .Map(dest => dest.Project, src => src.Project) + .Map(dest => dest.TotalAllowableCompensation, src => src.TotalAllowableCompensation) .Map(dest => dest.Stakeholders, src => src.PimsLeaseStakeholders) .Map(dest => dest.FileChecklistItems, src => src.PimsLeaseChecklistItems) .Map(dest => dest.PrimaryArbitrationCity, src => src.PrimaryArbitrationCity) @@ -100,6 +101,7 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.PimsLeaseChecklistItems, src => src.FileChecklistItems) .Map(dest => dest.PrimaryArbitrationCity, src => src.PrimaryArbitrationCity) .Map(dest => dest.ProjectId, src => src.Project != null ? src.Project.Id : (long?)null) + .Map(dest => dest.TotalAllowableCompensation, src => src.TotalAllowableCompensation) .Map(dest => dest.IsPublicBenefit, src => src.IsPublicBenefit) .Map(dest => dest.IsFinancialGain, src => src.IsFinancialGain) .Map(dest => dest.FeeDeterminationNote, src => src.FeeDeterminationNote) diff --git a/source/backend/dal/Repositories/CompReqFinancialRepository.cs b/source/backend/dal/Repositories/CompReqFinancialRepository.cs index 0149e076af..2dff5534a8 100644 --- a/source/backend/dal/Repositories/CompReqFinancialRepository.cs +++ b/source/backend/dal/Repositories/CompReqFinancialRepository.cs @@ -42,9 +42,26 @@ public IEnumerable GetAllByAcquisitionFileId(long acquisit { query = query.Where(c => c.CompensationRequisition.IsDraft == false); } + return query.AsNoTracking().ToArray(); } + public IEnumerable GetAllByLeaseFileId(long leaseFileId, bool? finalOnly) + { + this._user.ThrowIfNotAuthorized(Security.Permissions.CompensationRequisitionView); + + var query = Context.PimsCompReqFinancials + .Include(c => c.CompensationRequisition) + .Where(c => c.CompensationRequisition.LeaseId == leaseFileId); + + if (finalOnly == true) + { + query = query.Where(c => c.CompensationRequisition.IsDraft == false); + } + + return query.AsNoTracking().ToList(); + } + public IEnumerable SearchCompensationRequisitionFinancials(AcquisitionReportFilterModel filter) { using var scope = Logger.QueryScope(); diff --git a/source/backend/dal/Repositories/Interfaces/ICompReqFinancialRepository.cs b/source/backend/dal/Repositories/Interfaces/ICompReqFinancialRepository.cs index 766d62837f..ae0c500ad5 100644 --- a/source/backend/dal/Repositories/Interfaces/ICompReqFinancialRepository.cs +++ b/source/backend/dal/Repositories/Interfaces/ICompReqFinancialRepository.cs @@ -8,6 +8,8 @@ public interface ICompReqFinancialRepository : IRepository { IEnumerable GetAllByAcquisitionFileId(long acquisitionFileId, bool? finalOnly); + IEnumerable GetAllByLeaseFileId(long leaseFileId, bool? finalOnly); + IEnumerable SearchCompensationRequisitionFinancials(AcquisitionReportFilterModel filter); } } diff --git a/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs b/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs index 3ac2dea1a3..11ae3c07a2 100644 --- a/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs +++ b/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs @@ -449,7 +449,6 @@ public void Update_Status_BackToDraft_NoPermission() act.Should().Throw(); } - [Fact] public void Update_Status_BackToNull_NoPermission() { @@ -819,6 +818,88 @@ public void Update_Fail_ValidMultipleTotalAllowableCompensation() act.Should().Throw(); } + [Fact] + public void Update_Lease_Fail_ValidMultipleTotalAllowableCompensation() + { + // Arrange + var service = this.CreateCompRequisitionServiceWithPermissions(Permissions.CompensationRequisitionEdit); + var compReqFinancialsService = this._helper.GetService>(); + + var compRepository = this._helper.GetService>(); + var leaseRepository = this._helper.GetService>(); + + compRepository.Setup(x => x.Update(It.IsAny())) + .Returns(new PimsCompensationRequisition { Internal_Id = 1, LeaseId = 1, IsDraft = true }); ; + compRepository.Setup(x => x.GetById(It.IsAny())) + .Returns(new PimsCompensationRequisition { Internal_Id = 1, LeaseId = 1, IsDraft = null }); + + compReqFinancialsService.Setup(x => x.GetAllByLeaseFileId(It.IsAny(), true)).Returns( + new List() { new PimsCompReqFinancial() { CompensationRequisitionId = 1, TotalAmt = 1000 }, + new PimsCompReqFinancial() { CompensationRequisitionId = 2, TotalAmt = 100 }, }); + + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(new PimsLease() + { + TotalAllowableCompensation = 299, + PimsCompensationRequisitions = new List() { new PimsCompensationRequisition() { CompensationRequisitionId = 1, + PimsCompReqFinancials = new List() { new PimsCompReqFinancial() { TotalAmt = 100 } } }, }, + LeaseStatusTypeCode = LeaseStatusTypes.ACTIVE.ToString() + }); + + // Act + Action act = () => service.Update(FileTypes.Lease, new PimsCompensationRequisition() + { + Internal_Id = 1, + LeaseId = 1, + ConcurrencyControlNumber = 2, + IsDraft = false, + PimsCompReqFinancials = new List() { new PimsCompReqFinancial() { TotalAmt = 200 } }, + }); + + //Assert + act.Should().Throw(); + } + + [Fact] + public void Update_Lease_Fail_TotalAllowableExceeded() + { + // Arrange + var service = this.CreateCompRequisitionServiceWithPermissions(Permissions.CompensationRequisitionEdit); + var compReqFinancialsService = this._helper.GetService>(); + + var compRepository = this._helper.GetService>(); + var leaseRepository = this._helper.GetService>(); + + compRepository.Setup(x => x.Update(It.IsAny())) + .Returns(new PimsCompensationRequisition { Internal_Id = 1, LeaseId = 1, IsDraft = true }); ; + compRepository.Setup(x => x.GetById(It.IsAny())) + .Returns(new PimsCompensationRequisition { Internal_Id = 1, LeaseId = 1, IsDraft = null }); + + compReqFinancialsService.Setup(x => x.GetAllByLeaseFileId(It.IsAny(), true)).Returns( + new List() { new PimsCompReqFinancial() { CompensationRequisitionId = 1, TotalAmt = 1000 }, + new PimsCompReqFinancial() { CompensationRequisitionId = 2, TotalAmt = 100 }, }); + + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(new PimsLease() + { + TotalAllowableCompensation = 99, + PimsCompensationRequisitions = new List() { new PimsCompensationRequisition() { CompensationRequisitionId = 1, + PimsCompReqFinancials = new List() { new PimsCompReqFinancial() { TotalAmt = 100 } } }, }, + LeaseStatusTypeCode = LeaseStatusTypes.ACTIVE.ToString() + }); + + // Act + Action act = () => service.Update(FileTypes.Lease, new PimsCompensationRequisition() + { + Internal_Id = 1, + LeaseId = 1, + ConcurrencyControlNumber = 2, + IsDraft = false, + PimsCompReqFinancials = new List() { new PimsCompReqFinancial() { TotalAmt = 200 } }, + }); + + //Assert + act.Should().Throw(); + } + [Fact] public void Delete_NoPermission() { diff --git a/source/backend/tests/unit/api/Services/LeaseServiceTest.cs b/source/backend/tests/unit/api/Services/LeaseServiceTest.cs index 1fd7c89871..14f31b1e9d 100644 --- a/source/backend/tests/unit/api/Services/LeaseServiceTest.cs +++ b/source/backend/tests/unit/api/Services/LeaseServiceTest.cs @@ -9,6 +9,7 @@ using Pims.Api.Services; using Pims.Core.Exceptions; using Pims.Core.Test; +using Pims.Dal; using Pims.Dal.Entities; using Pims.Dal.Exceptions; using Pims.Dal.Repositories; @@ -299,6 +300,61 @@ public void Update_NoPermission() leaseRepository.Verify(x => x.Update(It.IsAny(), It.IsAny()), Times.Never); } + [Fact] + public void Update_NewTotalAllowableCompensation_Success() + { + // Arrange + var service = this.CreateLeaseService(Permissions.LeaseEdit); + + var currentLeaseEntity = EntityHelper.CreateLease(1, addProperty: false); + + var leaseRepository = this._helper.GetService>(); + var userRepository = this._helper.GetService>(); + var compReqFinancialRepository = this._helper.GetService>(); + + leaseRepository.Setup(x => x.GetNoTracking(It.IsAny())).Returns(currentLeaseEntity); + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(currentLeaseEntity); + + userRepository.Setup(x => x.GetByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + compReqFinancialRepository.Setup(c => c.GetAllByLeaseFileId(It.IsAny(), true)).Returns( + new List() { new PimsCompReqFinancial() { TotalAmt = 50 } }); + + // Act + currentLeaseEntity.TotalAllowableCompensation = 100; + var result = service.Update(currentLeaseEntity, new List()); + + // Assert + result.Should().NotBeNull(); + result.TotalAllowableCompensation.Equals(100); + } + + [Fact] + public void Update_NewTotalAllowableCompensation_Failure_LessThenCurrentFinancials() + { + // Arrange + var service = this.CreateLeaseService(Permissions.LeaseEdit); + + var currentLeaseEntity = EntityHelper.CreateLease(1, addProperty: false); + + var leaseRepository = this._helper.GetService>(); + var userRepository = this._helper.GetService>(); + var compReqFinancialRepository = this._helper.GetService>(); + + leaseRepository.Setup(x => x.GetNoTracking(It.IsAny())).Returns(currentLeaseEntity); + leaseRepository.Setup(x => x.Get(It.IsAny())).Returns(currentLeaseEntity); + + userRepository.Setup(x => x.GetByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + compReqFinancialRepository.Setup(c => c.GetAllByLeaseFileId(It.IsAny(), true)).Returns( + new List() { new PimsCompReqFinancial() { TotalAmt = 100 } }); + + // Act + currentLeaseEntity.TotalAllowableCompensation = 99; + Action act = () => service.Update(currentLeaseEntity, new List()); + + // Assert + act.Should().Throw(); + } + [Fact] public void Update_Without_StatusNote() { diff --git a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx index ecba5841d1..2f53d272a0 100644 --- a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx @@ -27,7 +27,6 @@ import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_C import { getMockApiLease } from '@/mocks/lease.mock'; import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease'; import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/ApiGen_Concepts_CompensationRequisition'; -import { getEmptyBaseAudit } from '@/models/defaultInitializers'; const storeState = { [lookupCodesSlice.name]: { lookupCodes: mockLookups }, @@ -63,6 +62,14 @@ const mockPutAcquisitionApi = { loading: false, }; +const mockPutLeaseApi = { + error: undefined, + response: { ...getMockApiLease(), totalAllowableCompensation: 1000 }, + execute: vi.fn(), + loading: false, +}; + + vi.mock('@/hooks/repositories/useRequisitionCompensationRepository', () => ({ useCompensationRequisitionRepository: () => { return { @@ -81,6 +88,14 @@ vi.mock('@/hooks/repositories/useAcquisitionProvider', () => ({ }, })); +vi.mock('@/hooks/repositories/useLeaseRepository', () => ({ + useLeaseRepository: () => { + return { + updateLease: mockPutLeaseApi, + }; + }, +})); + let viewProps: ICompensationListViewProps; const TestView: React.FC = props => { viewProps = props; @@ -323,7 +338,7 @@ describe('compensation list view container', () => { ); }); - it('returns an updated total allowable compensation if the update operation was successful', async () => { + it('returns an updated total allowable compensation for ACQUISITION if the update operation was successful', async () => { await setup({}); await act(async () => { viewProps?.onUpdateTotalCompensation(1000); @@ -338,6 +353,26 @@ describe('compensation list view container', () => { ); }); + it('returns an updated total allowable compensation for LEASE if the update operation was successful', async () => { + const leaseFileMock: ApiGen_Concepts_Lease = { ...getMockApiLease(), fileProperties: [] }; + + await setup({ + fileType: ApiGen_CodeTypes_FileTypes.Lease, + file: leaseFileMock, + }); + + await act(async () => { + viewProps?.onUpdateTotalCompensation(1000); + }); + + expect(mockPutLeaseApi.execute).toHaveBeenCalledWith( + expect.objectContaining({ + totalAllowableCompensation: 1000, + }), + [], + ); + }); + it('displays an error modal and throws an error if the api call fails', async () => { mockPutAcquisitionApi.execute.mockRejectedValue( createAxiosError(400, 'total allowable update error'), diff --git a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx index bf42ea6747..eb2893af8f 100644 --- a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx @@ -5,6 +5,7 @@ import { toast } from 'react-toastify'; import { SideBarContext } from '@/features/mapSideBar/context/sidebarContext'; import { useAcquisitionProvider } from '@/hooks/repositories/useAcquisitionProvider'; +import { useLeaseRepository } from '@/hooks/repositories/useLeaseRepository'; import { useCompensationRequisitionRepository } from '@/hooks/repositories/useRequisitionCompensationRepository'; import { getDeleteModalProps, useModalContext } from '@/hooks/useModalContext'; import { IApiError } from '@/interfaces/IApiError'; @@ -42,6 +43,10 @@ export const CompensationListContainer: React.FC } > - {fileType === ApiGen_CodeTypes_FileTypes.Acquisition && ( - <> - - - Total allowable compensation - - } - tooltip={`This is the maximum allowable for this file. Edit to set or change this value.`} - labelWidth="8" - className="summary-row" - valueClassName="text-right d-flex justify-content-end" - > - { - return (await onUpdateTotalCompensation(Number(value)))?.toString() ?? ''; - }} - initialValue={file.totalAllowableCompensation?.toString() ?? ''} - asCurrency - View={ToggleSaveInputView} - /> - -
- - )} + + + Total allowable compensation + + } + tooltip={`This is the maximum allowable for this file. Edit to set or change this value.`} + labelWidth="8" + className="summary-row" + valueClassName="text-right d-flex justify-content-end" + > + { + return (await onUpdateTotalCompensation(Number(value)))?.toString() ?? ''; + }} + initialValue={file.totalAllowableCompensation?.toString() ?? ''} + asCurrency + View={ToggleSaveInputView} + /> + +

+ diff --git a/source/frontend/src/hooks/repositories/useLeaseRepository.ts b/source/frontend/src/hooks/repositories/useLeaseRepository.ts index cdc1853b3f..a9972b38df 100644 --- a/source/frontend/src/hooks/repositories/useLeaseRepository.ts +++ b/source/frontend/src/hooks/repositories/useLeaseRepository.ts @@ -8,6 +8,7 @@ import { ApiGen_Concepts_FileWithChecklist } from '@/models/api/generated/ApiGen import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease'; import { ApiGen_Concepts_LeaseRenewal } from '@/models/api/generated/ApiGen_Concepts_LeaseRenewal'; import { ApiGen_Concepts_LeaseStakeholderType } from '@/models/api/generated/ApiGen_Concepts_LeaseStakeholderType'; +import { UserOverrideCode } from '@/models/api/UserOverrideCode'; import { useAxiosErrorHandler, useAxiosSuccessHandler } from '@/utils'; import { useApiLeases } from '../pims-api/useApiLeases'; @@ -19,6 +20,7 @@ export const useLeaseRepository = () => { const { getLastUpdatedByApi, getApiLease, + putApiLease, putLeaseChecklist, getLeaseChecklist, getLeaseRenewals, @@ -37,6 +39,21 @@ export const useLeaseRepository = () => { onError: useAxiosErrorHandler('Failed to retreive last-updated-by information for a lease.'), }); + const updateApiLease = useApiRequestWrapper< + ( + lease: ApiGen_Concepts_Lease, + userOverrideCodes: UserOverrideCode[], + ) => Promise> + >({ + requestFunction: useCallback( + async (lease: ApiGen_Concepts_Lease, userOverrideCodes: UserOverrideCode[] = []) => + await putApiLease(lease, userOverrideCodes), + [putApiLease], + ), + requestName: 'updateLease', + throwError: true, + }); + const getLease = useApiRequestWrapper< (leaseId: number) => Promise> >({ @@ -100,6 +117,7 @@ export const useLeaseRepository = () => { return useMemo( () => ({ getLastUpdatedBy: getLastUpdatedBy, + updateLease: updateApiLease, getLease: getLease, getLeaseRenewals: getLeaseRenewalsApi, getLeaseChecklist: getLeaseChecklistApi, @@ -108,6 +126,7 @@ export const useLeaseRepository = () => { }), [ getLastUpdatedBy, + updateApiLease, getLease, getLeaseRenewalsApi, getLeaseChecklistApi, diff --git a/source/frontend/src/mocks/lease.mock.ts b/source/frontend/src/mocks/lease.mock.ts index 6f40c42a62..80e1b62b25 100644 --- a/source/frontend/src/mocks/lease.mock.ts +++ b/source/frontend/src/mocks/lease.mock.ts @@ -387,6 +387,7 @@ export const getMockApiLease: () => ApiGen_Concepts_Lease = () => ({ primaryContactId: null, }, ], + totalAllowableCompensation: null, properties: [], insurances: [], leasePurposes: [