-
Notifications
You must be signed in to change notification settings - Fork 35
/
budget.go
58 lines (43 loc) · 1.18 KB
/
budget.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package model
import (
"errors"
"github.com/openaccounting/oa-server/core/model/types"
)
type BudgetInterface interface {
GetBudget(string, string) (*types.Budget, error)
CreateBudget(*types.Budget, string) error
DeleteBudget(string, string) error
}
func (model *Model) GetBudget(orgId string, userId string) (*types.Budget, error) {
belongs, err := model.UserBelongsToOrg(userId, orgId)
if err != nil {
return nil, err
}
if belongs == false {
return nil, errors.New("User does not belong to org")
}
return model.db.GetBudget(orgId)
}
func (model *Model) CreateBudget(budget *types.Budget, userId string) error {
belongs, err := model.UserBelongsToOrg(userId, budget.OrgId)
if err != nil {
return err
}
if belongs == false {
return errors.New("User does not belong to org")
}
if budget.OrgId == "" {
return errors.New("orgId required")
}
return model.db.InsertAndReplaceBudget(budget)
}
func (model *Model) DeleteBudget(orgId string, userId string) error {
belongs, err := model.UserBelongsToOrg(userId, orgId)
if err != nil {
return err
}
if belongs == false {
return errors.New("User does not belong to org")
}
return model.db.DeleteBudget(orgId)
}