Skip to content

Commit

Permalink
Merge pull request #2396 from sophiemoustard/COM-3726
Browse files Browse the repository at this point in the history
COM-3726: update helper return
  • Loading branch information
sophiemoustard committed Jun 19, 2024
2 parents 70f1925 + 6e9fbc4 commit cc3fc6b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/controllers/taxCertificateController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const generateTaxCertificatePdf = async (req, h) => {
req.log('taxCertificateController - generateTaxCertificatePdf - params', req.params);
req.log('taxCertificateController - generateTaxCertificatePdf - company', get(req, 'auth.credentials.company._id'));

const pdf = await TaxCertificateHelper.generateTaxCertificatePdf(req.params._id, req.auth.credentials);
const { pdf, filename } = await TaxCertificateHelper
.generateTaxCertificatePdf(req.params._id, req.auth.credentials);

return h.response(pdf)
.header('content-disposition', 'inline; filename=taxcertificates.pdf')
.header('content-disposition', `inline; filename=${filename}.pdf`)
.type('application/pdf');
} catch (e) {
req.log('error', e);
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/taxCertificates.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ exports.generateTaxCertificatePdf = async (taxCertificateId, credentials) => {
const payments = await PaymentRepository.getTaxCertificatesPayments(taxCertificate, companyId);

const data = exports.formatPdf(taxCertificate, credentials.company, interventions, payments);
const pdf = await TaxCertificatePdf.getPdf(data);

return TaxCertificatePdf.getPdf(data);
return { pdf, filename: `attestation_fiscale_${taxCertificate.year}` };
};

exports.remove = async (taxCertificateId) => {
Expand Down
2 changes: 2 additions & 0 deletions src/repositories/PaymentRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ exports.getTaxCertificatesPayments = async (taxCertificate, companyId) => {
},
]).option({ company: companyId });

if (!paidPrice[0]) return { paid: 0, cesu: 0 };

const payments = paidPrice[0].payments
.reduce((acc, p) => NumbersHelper.add(acc, p.netInclTaxes), NumbersHelper.toString(0));
const refunds = paidPrice[0].refunds
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/helpers/taxCertificates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('generateTaxCertificatePdf', () => {

const result = await TaxCertificateHelper.generateTaxCertificatePdf(taxCertificateId, credentials);

expect(result).toEqual('pdf');
expect(result).toEqual({ filename: 'attestation_fiscale_2019', pdf: 'pdf' });
SinonMongoose.calledOnceWithExactly(
findOne,
[
Expand Down

0 comments on commit cc3fc6b

Please sign in to comment.