perf: refs #7356 minor changes
gitea/salix-front/pipeline/pr-test There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2025-03-02 23:50:23 +01:00
parent ba98816f93
commit 947024ef56
1 changed files with 8 additions and 11 deletions

View File

@ -121,21 +121,21 @@ async function handleSave() {
isSaving.value = false;
}
}
function validateFields(item, isUpdate = false) {
function validateFields(item) {
// Only validate fields that are being updated
const shouldValidate = (field) => !isUpdate || field in item;
const shouldExist = (field) => !isUpdate || field in item;
if (shouldValidate('ticketServiceTypeFk') && !item.ticketServiceTypeFk) {
notify('Descriptssion is required', 'negative');
if (!shouldExist('ticketServiceTypeFk') && !item.ticketServiceTypeFk) {
notify('Description is required', 'negative');
return false;
}
if (shouldValidate('quantity') && (!item.quantity || item.quantity <= 0)) {
if (!shouldExist('quantity') && (!item.quantity || item.quantity <= 0)) {
notify('Quantity must be greater than 0', 'negative');
return false;
}
if (shouldValidate('price') && (item.price === null || item.price < 0)) {
if (!shouldExist('price') && (!item.price || item.price < 0)) {
notify('Price must be valid', 'negative');
return false;
}
@ -150,20 +150,17 @@ function beforeSave(data) {
// Validate creates
if (creates.length) {
for (const create of creates) {
create.ticketFk = route.params.id;
if (validateFields(create)) {
validData.creates.push(create);
}
create.ticketFk = route.params.id;
}
}
// Validate updates
if (updates.length) {
for (const update of updates) {
if (validateFields(update, true)) {
validData.updates.push(update);
return false;
}
validData.updates.push(update);
}
}
return validData;