/
procedure_history.go
71 lines (53 loc) · 1.52 KB
/
procedure_history.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
59
60
61
62
63
64
65
66
67
68
69
70
71
package models
import (
arangoDB "github.com/hostelix/aranGO"
"github.com/merakiVE/CVDI/core/types"
"github.com/merakiVE/CVDI/core/validator"
"github.com/merakiVE/CVDI/core/tags"
)
type Stage struct {
Code string `json:"code"`
Name string `json:"name"`
Description string `json:"description"`
IsCurrent bool `json:"is_current"`
}
type ProcedureHistoryModel struct {
arangoDB.Document
ProcedureID string `json:"id" validate:"required" on_create:"set,auto_uuid"`
UserID string `json:"user_id,omitempty" validate:"required"`
Stages []Stage `json:"stage"`
types.Timestamps
ErrorsValidation []map[string]string `json:"errors_validation,omitempty"`
}
func (this ProcedureHistoryModel) GetKey() string {
return this.Key
}
func (this ProcedureHistoryModel) GetCollection() string {
return "procedure_history"
}
func (this ProcedureHistoryModel) GetError() (string, bool) {
return this.Message, this.Error
}
func (this ProcedureHistoryModel) GetValidationErrors() ([]map[string]string) {
return this.ErrorsValidation
}
func (this *ProcedureHistoryModel) PreSave(c *arangoDB.Context) {
v := validator.New()
v.Validate(this)
if v.IsValid() {
//Tag Process for model
tags.New().ProcessTags(this)
} else {
c.Err["error_validation"] = "Error validating model"
this.ErrorsValidation = v.GetMessagesValidation()
}
return
}
/*
func (this ProcedureHistoryModel) GetCurrentStage() Stage {
for _, value := range this.Stages {
if value.IsCurrent {
return value
}
}
}*/