From 1924bfca2439829253df3598481034e5c586e3e2 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 9 Oct 2023 21:07:20 +0530 Subject: added route to add items to invoice --- invoice/validators.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'invoice/validators.go') diff --git a/invoice/validators.go b/invoice/validators.go index 645bdff..9f145dc 100644 --- a/invoice/validators.go +++ b/invoice/validators.go @@ -18,12 +18,7 @@ package invoice import ( - //"regexp" - //"strings" - //"net/mail" - //"net/url" "vidhukant.com/openbills/errors" - //e "errors" ) func (i *Invoice) validate() error { @@ -44,6 +39,27 @@ func (i *Invoice) validate() error { return nil } +func isDraft(invoiceId uint) (bool, error) { + var invoice Invoice + err := db. + Select("id", "is_draft"). + Where("id = ?", invoiceId). + Find(&invoice). + Error + + // TODO: handle potential errors + if err != nil { + return invoice.IsDraft, err + } + + // invoice doesn't exist + if invoice.ID == 0 { + return invoice.IsDraft, errors.ErrNotFound + } + + return invoice.IsDraft, nil +} + func checkInvoiceOwnership(invoiceId, userId uint) error { var invoice Invoice err := db. -- cgit v1.2.3