#7356 - TicketServices and CrudModel updates #1479

Merged
jsegarra merged 6 commits from 7356_ticketService into test 2025-03-03 12:06:24 +00:00
1 changed files with 8 additions and 11 deletions
Showing only changes of commit 947024ef56 - Show all commits

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;
}
}
}
return validData;