feat!: implement downloads for contracts (EN-331)
Summary
Implemented functionality to generate and download PDF documents based on contract details.
Changes
- Created
src/utils/createContractPDF.js
file that uses pdf-lib to generate a PDF using a passed in contract object to fill in certain fields - Added route
/api/v2/contracts/:id/download
with validation (uses "manageContracts" permission that admins and loan officers have) - Added service that calls the
createContractPDF
function (from src/utils/createContractPDF.js) and returns the file name - Added controller that uses
res.download
to download a PDF using file path and file name provided by contracts service layer - Added tests to ensure downloads work by checking headers and the file system (PDFs generated by the tests are deleted to avoid clutter)