fix(invoice): was storing invoices on incorrect path folder
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-09-30 14:43:37 +02:00
parent 479d4892ce
commit 54fa419255
3 changed files with 7 additions and 6 deletions

View File

@ -61,12 +61,12 @@ module.exports = Self => {
const created = invoiceOut.created;
const year = created.getFullYear().toString();
const month = created.getMonth().toString();
const month = (created.getMonth() + 1).toString();
const day = created.getDate().toString();
const container = await models.InvoiceContainer.container(year);
const rootPath = container.client.root;
const fileName = `${invoiceOut.ref}.pdf`;
const fileName = `${year}${invoiceOut.ref}.pdf`;
const src = path.join(rootPath, year, month, day);
fileSrc = path.join(src, fileName);

View File

@ -47,13 +47,13 @@ module.exports = Self => {
const created = invoiceOut.created;
const year = created.getFullYear().toString();
const month = created.getMonth().toString();
const month = (created.getMonth() + 1).toString();
const day = created.getDate().toString();
const container = await models.InvoiceContainer.container(year);
const rootPath = container.client.root;
const src = path.join(rootPath, year, month, day);
const fileName = `${invoiceOut.ref}.pdf`;
const fileName = `${year}${invoiceOut.ref}.pdf`;
const fileSrc = path.join(src, fileName);
// Creates PDF document if it has not been created
@ -63,13 +63,14 @@ module.exports = Self => {
const file = {
path: fileSrc,
contentType: 'application/pdf',
name: `${id}.pdf`
name: fileName
};
await fs.access(file.path);
let stream = fs.createReadStream(file.path);
return [stream, file.contentType, `filename="${file.name}"`];
} catch (error) {
console.log(error);
if (error.code === 'ENOENT')
throw new UserError('The PDF document does not exists');

View File

@ -23,6 +23,6 @@ describe('InvoiceOut download()', () => {
const result = await models.InvoiceOut.download(ctx, invoiceId);
expect(result[1]).toEqual('application/pdf');
expect(result[2]).toEqual('filename="1.pdf"');
expect(result[2]).toEqual('filename="2021T1111111.pdf"');
});
});