-
Notifications
You must be signed in to change notification settings - Fork 0
/
attachments.js
44 lines (39 loc) · 1013 Bytes
/
attachments.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const path = require('path');
const fs = require('fs');
const invoicePath = path.join(__dirname, 'invoices');
class Attachments {
constructor(id){
this.id = id;
}
// Encodes attachments.
encodedList(callback){
this.getInvoices(function(err, invoices){
if(err){
return console.log(err);
} else {
let encodedAttachments = [];
for(let i = 0; i < invoices.length; i++){
encodedAttachments[i] = {
path: `${invoicePath}/${invoices[i]}`,
encoding: 'base64'
}
}
callback(encodedAttachments);
}
});
}
// Retrieves invoices from invoices directory using employerGroupId.
getInvoices(callback){
let employerId = this.id.toString();
fs.readdir(invoicePath, function(err, files){
callback(
err,
files.filter(function(file){
let id = file.split('_')[0];
return id === employerId;
})
);
});
}
}
module.exports = Attachments;