aboutsummaryrefslogtreecommitdiff
path: root/invoice/validators.go
diff options
context:
space:
mode:
Diffstat (limited to 'invoice/validators.go')
-rw-r--r--invoice/validators.go26
1 files changed, 21 insertions, 5 deletions
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.