0
0
Fork 0

fix: #5926 fix downdload function

This commit is contained in:
Javier Segarra 2024-06-17 10:08:08 +02:00
parent c626a10a98
commit ea0398df61
1 changed files with 30 additions and 27 deletions

View File

@ -14,7 +14,7 @@ import VnPaginate from 'src/components/ui/VnPaginate.vue';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
import VnSelect from 'src/components/common/VnSelect.vue'; import VnSelect from 'src/components/common/VnSelect.vue';
import VnInput from 'src/components/common/VnInput.vue'; import VnInput from 'src/components/common/VnInput.vue';
const FILECABINET_ID = 'hr';
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
const loadingDocuware = ref(true); const loadingDocuware = ref(true);
@ -52,13 +52,13 @@ function reloadData() {
const handleSendToTablet = async (row) => { const handleSendToTablet = async (row) => {
try { try {
// if (isProduction(false)) { if (isProduction(false)) {
const { deviceProductionFk } = row; const { deviceProductionFk } = row;
await axios.post(`Docuwares/upload`, { await axios.post(`Docuwares/upload`, {
fileCabinet: 'hr', fileCabinet: FILECABINET_ID,
ids: [deviceProductionFk], ids: [deviceProductionFk],
}); });
// } }
notify(t('PDF sended to signed'), 'positive'); notify(t('PDF sended to signed'), 'positive');
row.isDocuware = true; row.isDocuware = true;
} catch (err) { } catch (err) {
@ -67,7 +67,7 @@ const handleSendToTablet = async (row) => {
}; };
function checkFileFocuware({ deviceProductionFk }, signed) { function checkFileFocuware({ deviceProductionFk }, signed) {
return axios.post(`Docuwares/${deviceProductionFk}/checkFile`, { return axios.post(`Docuwares/${deviceProductionFk}/checkFile`, {
fileCabinet: 'hr', fileCabinet: FILECABINET_ID,
signed, signed,
}); });
} }
@ -86,8 +86,8 @@ const handleDownloadDocuware = async (row) => {
try { try {
if (isProduction(false)) { if (isProduction(false)) {
const { deviceProductionFk } = row; const { deviceProductionFk } = row;
await axios.post(`Docuwares/upload`, { await axios.post(`Docuwares/download`, {
fileCabinet: 'hr', fileCabinet: FILECABINET_ID,
ids: [deviceProductionFk], ids: [deviceProductionFk],
}); });
} }
@ -96,30 +96,33 @@ const handleDownloadDocuware = async (row) => {
console.error('Error removing department'); console.error('Error removing department');
} }
}; };
function handlePromiseDocuware(promise, deviceProductions) {
async function fetchDocuware(deviceProductions) { const id = +promise.config.url.match(/\d+/)[0];
let promisesIsDocuware = deviceProductions.map((device) => const deviceProduction = deviceProductions.find(
checkFileFocuware(device, false) ({ deviceProductionFk }) => deviceProductionFk === id
); );
return deviceProduction;
}
async function fetchDocuware(deviceProductions) {
const promisesIsDocuware = await Promise.allSettled(
deviceProductions.map((device) => checkFileFocuware(device, false))
);
let promisesIsSigned = []; let promisesIsSigned = [];
promisesIsDocuware = await Promise.all(promisesIsDocuware); promisesIsDocuware.forEach(({ value: promise }) => {
promisesIsDocuware.forEach((promise) => { const deviceProduction = handlePromiseDocuware(promise, deviceProductions);
const id = +promise.config.url.match(/\d+/)[0];
const deviceProduction = deviceProductions.find(
({ deviceProductionFk }) => deviceProductionFk === id
);
if (!deviceProduction) return; if (!deviceProduction) return;
deviceProduction.isDocuware = promise.data; deviceProduction.isDocuware = promise.data;
if (promise.data) if (promise.data)
promisesIsSigned.push(checkFileFocuware(deviceProduction, true)); promisesIsSigned.push(checkFileFocuware(deviceProduction, true));
}); });
promisesIsSigned = await Promise.all(promisesIsSigned);
promisesIsSigned.forEach((promise) => { promisesIsSigned = await Promise.allSettled(promisesIsSigned);
const id = +promise.config.url.match(/\d+/)[0]; promisesIsSigned.forEach(({ value: promise }) => {
const deviceProduction = deviceProductions.find( const deviceProduction = handlePromiseDocuware(promise, deviceProductions);
({ deviceProductionFk }) => deviceProductionFk === id
);
if (!deviceProduction) return; if (!deviceProduction) return;
deviceProduction.isSigned = !!promise.data.id; deviceProduction.isSigned = !!promise.data.id;
}); });