perf: cleancode
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-07-04 10:40:11 +02:00
parent c25b04e075
commit 4a01f1d930
1 changed files with 23 additions and 43 deletions

View File

@ -246,9 +246,9 @@ const saleTrackingNew = async (sale, stateCode, isChecked) => {
try { try {
const params = { const params = {
saleFk: sale.saleFk, saleFk: sale.saleFk,
isChecked: isChecked, isChecked,
quantity: sale.quantity, quantity: sale.quantity,
stateCode: stateCode, stateCode,
}; };
await axios.post(`SaleTrackings/new`, params); await axios.post(`SaleTrackings/new`, params);
notify(t('globals.dataSaved'), 'positive'); notify(t('globals.dataSaved'), 'positive');
@ -257,10 +257,10 @@ const saleTrackingNew = async (sale, stateCode, isChecked) => {
} }
}; };
const saleTrackingDel = async (sale, stateCode) => { const saleTrackingDel = async ({ saleFk }, stateCode) => {
try { try {
const params = { const params = {
saleFk: sale.saleFk, saleFk,
stateCodes: [stateCode], stateCodes: [stateCode],
}; };
await axios.post(`SaleTrackings/delete`, params); await axios.post(`SaleTrackings/delete`, params);
@ -284,14 +284,8 @@ const clickSaleGroupDetail = async (sale) => {
const clickPreviousSelected = (sale) => { const clickPreviousSelected = (sale) => {
try { try {
if (!sale.isPreviousSelected) { qCheckBoxController(sale, 'isPreviousSelected');
saleTrackingNew(sale, 'PREVIOUS_PREPARATION', false); if (!sale.isPreviousSelected) sale.isPrevious = false;
sale.isPreviousSelected = true;
} else {
saleTrackingDel(sale, 'PREVIOUS_PREPARATION');
sale.isPreviousSelected = false;
sale.isPrevious = false;
}
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -299,41 +293,28 @@ const clickPreviousSelected = (sale) => {
const clickPrevious = (sale) => { const clickPrevious = (sale) => {
try { try {
if (!sale.isPrevious) { qCheckBoxController(sale, 'isPrevious');
saleTrackingNew(sale, 'PREVIOUS_PREPARATION', true); if (sale.isPrevious) sale.isPreviousSelected = true;
sale.isPrevious = true;
sale.isPreviousSelected = true;
} else {
saleTrackingNew(sale, 'PREVIOUS_PREPARATION', false);
sale.isPrevious = false;
}
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
}; };
const clickPrepared = (sale) => { const qCheckBoxController = (sale, action) => {
const STATE_CODES = {
isControled: 'CHECKED',
isPrepared: 'PREPARED',
isPrevious: 'PREVIOUS_PREPARATION',
isPreviousSelected: 'PREVIOUS_PREPARATION',
};
const stateCode = STATE_CODES[action];
try { try {
if (!sale.isPrepared) { if (!sale[action]) {
saleTrackingNew(sale, 'PREPARED', true); saleTrackingNew(sale, stateCode, true);
sale.isPrepared = true; sale[action] = true;
} else { } else {
saleTrackingDel(sale, 'PREPARED'); saleTrackingDel(sale, stateCode);
sale.isPrepared = false; sale[action] = false;
}
} catch (error) {
console.error(error);
}
};
const clickControled = (sale) => {
try {
if (!sale.isControled) {
saleTrackingNew(sale, 'CHECKED', true);
sale.isControled = true;
} else {
saleTrackingDel(sale, 'CHECKED');
sale.isControled = false;
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -403,7 +384,7 @@ const clickControled = (sale) => {
color="warning" color="warning"
class="warning" class="warning"
:toggle-indeterminate="false" :toggle-indeterminate="false"
@update:model-value="clickPrepared(row)" @update:model-value="qCheckBoxController(row, 'isPrepared')"
> >
<QTooltip> <QTooltip>
{{ t('ticketSaleTracking.prepared') }} {{ t('ticketSaleTracking.prepared') }}
@ -413,9 +394,8 @@ const clickControled = (sale) => {
:model-value="!!row.isControled" :model-value="!!row.isControled"
color="yellow" color="yellow"
class="yellow" class="yellow"
style="stroke: red"
:toggle-indeterminate="false" :toggle-indeterminate="false"
@update:model-value="clickControled(row)" @update:model-value="qCheckBoxController(row, 'isControled')"
> >
<QTooltip> <QTooltip>
{{ t('ticketSaleTracking.checked') }} {{ t('ticketSaleTracking.checked') }}