From 63cf602ab24340e9128cb3511b41f4618e6b2202 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 21 Mar 2025 11:46:42 +0100 Subject: [PATCH] refactor(WorkerPda): refs #5926 optimize fetchDocuware and sendToTablet functions for better readability --- src/pages/Worker/Card/WorkerPda.vue | 64 +++++++++++++---------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/src/pages/Worker/Card/WorkerPda.vue b/src/pages/Worker/Card/WorkerPda.vue index 104f45556..27313e52c 100644 --- a/src/pages/Worker/Card/WorkerPda.vue +++ b/src/pages/Worker/Card/WorkerPda.vue @@ -88,48 +88,40 @@ function reloadData() { async function fetchDocuware() { loadingDocuware.value = true; - const id = worker.value?.lastName + ' ' + worker.value?.firstName; - const promises = []; - for (const row of tableRef.value.CrudModelRef.formData) { - promises.push( - (async () => { - const { data } = await axios.post(`Docuwares/${id}/checkFile`, { - fileCabinet: 'hr', - signed: false, - mergeFilter: [ - { - DBName: 'TIPO_DOCUMENTO', - Value: ['PDA'], - }, - { - DBName: 'FILENAME', - Value: [row.deviceProductionFk + '-pda'], - }, - ], - }); - row.docuware = data; - })(), - ); - } + const id = `${worker.value?.lastName} ${worker.value?.firstName}`; + const rows = tableRef.value.CrudModelRef.formData; - await Promise.all(promises); + const promises = rows.map(async (row) => { + const { data } = await axios.post(`Docuwares/${id}/checkFile`, { + fileCabinet: 'hr', + signed: false, + mergeFilter: [ + { + DBName: 'TIPO_DOCUMENTO', + Value: ['PDA'], + }, + { + DBName: 'FILENAME', + Value: [`${row.deviceProductionFk}-pda`], + }, + ], + }); + row.docuware = data; + }); + + await Promise.allSettled(promises); loadingDocuware.value = false; } async function sendToTablet(rows) { - const promises = []; - for (const row of rows) { - promises.push( - (async () => { - await axios.post(`Docuwares/upload-pda-pdf`, { - ids: [row.deviceProductionFk], - }); - row.docuware = true; - })(), - ); - } - await Promise.all(promises); + const promises = rows.map(async (row) => { + await axios.post(`Docuwares/upload-pda-pdf`, { + ids: [row.deviceProductionFk], + }); + row.docuware = true; + }); + await Promise.allSettled(promises); notify(t('PDF sended to signed'), 'positive'); tableRef.value.reload(); }