#7356 - TicketServices and CrudModel updates #1479
|
@ -121,21 +121,21 @@ async function handleSave() {
|
||||||
isSaving.value = false;
|
isSaving.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function validateFields(item, isUpdate = false) {
|
function validateFields(item) {
|
||||||
// Only validate fields that are being updated
|
// 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) {
|
if (!shouldExist('ticketServiceTypeFk') && !item.ticketServiceTypeFk) {
|
||||||
notify('Descriptssion is required', 'negative');
|
notify('Description is required', 'negative');
|
||||||
return false;
|
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');
|
notify('Quantity must be greater than 0', 'negative');
|
||||||
return false;
|
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');
|
notify('Price must be valid', 'negative');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -150,20 +150,17 @@ function beforeSave(data) {
|
||||||
// Validate creates
|
// Validate creates
|
||||||
if (creates.length) {
|
if (creates.length) {
|
||||||
for (const create of creates) {
|
for (const create of creates) {
|
||||||
|
create.ticketFk = route.params.id;
|
||||||
if (validateFields(create)) {
|
if (validateFields(create)) {
|
||||||
validData.creates.push(create);
|
validData.creates.push(create);
|
||||||
}
|
}
|
||||||
create.ticketFk = route.params.id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate updates
|
// Validate updates
|
||||||
if (updates.length) {
|
if (updates.length) {
|
||||||
for (const update of updates) {
|
for (const update of updates) {
|
||||||
if (validateFields(update, true)) {
|
validData.updates.push(update);
|
||||||
validData.updates.push(update);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return validData;
|
return validData;
|
||||||
|
|
Loading…
Reference in New Issue