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