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 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)) {
if (isProduction(false)) {
const { deviceProductionFk } = row;
await axios.post(`Docuwares/upload`, {
fileCabinet: 'hr',
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)
);
let promisesIsSigned = [];
promisesIsDocuware = await Promise.all(promisesIsDocuware);
promisesIsDocuware.forEach((promise) => {
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.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;
});