/
procedure_session.go
52 lines (39 loc) · 1.21 KB
/
procedure_session.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
package models
import (
arangoDB "github.com/hostelix/aranGO"
"github.com/merakiVE/CVDI/core/validator"
"github.com/merakiVE/CVDI/core/tags"
)
type ProcedureSessionModel struct {
arangoDB.Document
ID string `json:"id" on_create:"set,auto_uuid"`
ProcedureID string `json:"procedure_id" validate:"required"`
UserID string `json:"user_id,omitempty" validate:"required"`
CurrentStage int `json:"stage"`
ErrorsValidation []map[string]string `json:"errors_validation,omitempty"`
}
func (this ProcedureSessionModel) GetKey() string {
return this.Key
}
func (this ProcedureSessionModel) GetCollection() string {
return "procedure_session"
}
func (this ProcedureSessionModel) GetError() (string, bool) {
return this.Message, this.Error
}
func (this ProcedureSessionModel) GetValidationErrors() ([]map[string]string) {
return this.ErrorsValidation
}
func (this *ProcedureSessionModel) PreSave(c *arangoDB.Context) {
v := validator.New()
v.Validate(this)
if v.IsValid() {
//Tag Process for model
t := tags.New()
t.ProcessTags(this)
} else {
c.Err["error_validation"] = "Error validating model"
this.ErrorsValidation = v.GetMessagesValidation()
}
return
}