From 48845b9e703756471a98f8b1f1edaa2313763df4 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 9 Oct 2023 22:11:16 +0530 Subject: checking user while adding and removing invoice items --- invoice/hooks.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'invoice/hooks.go') diff --git a/invoice/hooks.go b/invoice/hooks.go index 686500a..7a59352 100644 --- a/invoice/hooks.go +++ b/invoice/hooks.go @@ -70,3 +70,18 @@ func (i *InvoiceItem) BeforeSave(tx *gorm.DB) error { return nil } + +func (i *InvoiceItem) BeforeDelete(tx *gorm.DB) error { + var err error + + isDraft, err := isDraft(i.InvoiceID) + if err != nil { + return err + } + + if !isDraft { + return errors.ErrCannotEditInvoice + } + + return nil +} -- cgit v1.2.3