feat: Attachment files system.

This commit is contained in:
Ahmed Bouhuolia
2020-05-04 05:11:44 +02:00
parent a807cf6bb8
commit 7f06e3781c
35 changed files with 757 additions and 179 deletions

View File

@@ -1,6 +1,7 @@
import moment from 'moment';
import _ from 'lodash';
import Currency from 'js-money/lib/currency';
import PProgress from 'p-progress';
import accounting from 'accounting';
@@ -151,4 +152,22 @@ export const checkRequiredProperties = (obj, properties) => {
const value = obj[prop];
return (value === '' || value === null || value === undefined);
})
}
}
export const saveFilesInAsync = (files, actionCb, extraTasks) => {
const opers = [];
files.forEach((file) => {
const formData = new FormData();
formData.append('attachment', file.file);
const oper = new PProgress((resolve, reject, progress) => {
actionCb(formData, file, (requestProgress) => {
progress(requestProgress);
})
.then((data) => { resolve(data); })
.catch(error => { reject(error); })
});
opers.push(oper);
});
return PProgress.all(opers);
}