mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-28 08:21:08 -04:00
Fix edge cases with error handling.
This commit is contained in:
@ -58,9 +58,9 @@ class InvoiceService {
|
|||||||
number: 'Number',
|
number: 'Number',
|
||||||
};
|
};
|
||||||
|
|
||||||
const errors = validate(requiredFields, invoice);
|
const res = validate(requiredFields, invoice);
|
||||||
if (Object.keys(errors).length > 0) {
|
if (Object.keys(res.errors).length > 0) {
|
||||||
return Promise.reject(errors);
|
return Promise.reject(res);
|
||||||
}
|
}
|
||||||
const invoices = await this.getInvoices();
|
const invoices = await this.getInvoices();
|
||||||
const index = invoices.findIndex(item => item.id === invoice.id);
|
const index = invoices.findIndex(item => item.id === invoice.id);
|
||||||
@ -100,7 +100,6 @@ class InvoiceService {
|
|||||||
from_phone: 'From Phone',
|
from_phone: 'From Phone',
|
||||||
bank_name: 'Bank Name',
|
bank_name: 'Bank Name',
|
||||||
bank_account_no: 'Bank Account No.',
|
bank_account_no: 'Bank Account No.',
|
||||||
project_id: 'Project Id',
|
|
||||||
rows: {
|
rows: {
|
||||||
item: 'Item',
|
item: 'Item',
|
||||||
quantity: 'Quantity',
|
quantity: 'Quantity',
|
||||||
@ -109,9 +108,9 @@ class InvoiceService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const errors = await validate(requiredFields, invoice);
|
const res = await validate(requiredFields, invoice);
|
||||||
if (Object.keys(errors).length > 0) {
|
if (Object.keys(res.errors).length > 0) {
|
||||||
return Promise.reject(errors);
|
return Promise.reject(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
invoice.status = 'booked';
|
invoice.status = 'booked';
|
||||||
|
|||||||
@ -150,19 +150,12 @@ export default {
|
|||||||
async removeRow(store, row) {
|
async removeRow(store, row) {
|
||||||
await InvoiceRow.delete(row.id);
|
await InvoiceRow.delete(row.id);
|
||||||
},
|
},
|
||||||
async sendInvoice({ state, dispatch }, message) {
|
|
||||||
const res = await InvoiceService.sendInvoice(state.invoiceId, message);
|
|
||||||
dispatch('invoiceProps', {
|
|
||||||
status: 'sent',
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
},
|
|
||||||
async bookInvoice({ getters, commit, dispatch }) {
|
async bookInvoice({ getters, commit, dispatch }) {
|
||||||
commit('clearErrors');
|
commit('clearErrors');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await InvoiceService.bookInvoice(getters.invoice);
|
await InvoiceService.bookInvoice(getters.invoice);
|
||||||
return dispatch('getInvoice', res.invoice_id);
|
return dispatch('getInvoice', getters.invoice.id);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
commit('setErrors', err.errors);
|
commit('setErrors', err.errors);
|
||||||
}
|
}
|
||||||
@ -171,7 +164,7 @@ export default {
|
|||||||
getters: {
|
getters: {
|
||||||
invoice(state) {
|
invoice(state) {
|
||||||
return Invoice.query()
|
return Invoice.query()
|
||||||
.with(['client', 'project', 'team.logos'])
|
.with(['client'])
|
||||||
.with('rows', query => query.orderBy('order', 'asc'))
|
.with('rows', query => query.orderBy('order', 'asc'))
|
||||||
.find(state.invoiceId);
|
.find(state.invoiceId);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user