feat (patient): add patient employee checker
This commit is contained in:
No files matched your search
@@ -103,3 +103,7 @@ func (a AuthInfo) IsNurseIntern() bool {
|
|||||||
func (a AuthInfo) HasEmployeePosition() bool {
|
func (a AuthInfo) HasEmployeePosition() bool {
|
||||||
return a.Employee_Position_Code != nil
|
return a.Employee_Position_Code != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AuthInfo) IsReg() bool {
|
||||||
|
return a.Employee_Position_Code != nil && *a.Employee_Position_Code == string(ero.EPCReg)
|
||||||
|
}
|
||||||
@@ -50,6 +50,16 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
return nil, pl.SetLogError(&event, input)
|
return nil, pl.SetLogError(&event, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !input.AuthInfo.IsReg() {
|
||||||
|
event.Status = "failed"
|
||||||
|
event.ErrInfo = pl.ErrorInfo{
|
||||||
|
Code: "auth-forbidden",
|
||||||
|
Detail: "user role is not allowed to create patient, only 'reg' position is allowed",
|
||||||
|
Raw: errors.New("authentication failed"),
|
||||||
|
}
|
||||||
|
return nil, pl.SetLogError(&event, input)
|
||||||
|
}
|
||||||
|
|
||||||
input.RegisteredBy_User_Name = &input.AuthInfo.User_Name
|
input.RegisteredBy_User_Name = &input.AuthInfo.User_Name
|
||||||
|
|
||||||
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
||||||
@@ -256,6 +266,16 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
pl.SetLogInfo(&event, input, "started", "update")
|
pl.SetLogInfo(&event, input, "started", "update")
|
||||||
mwRunner := newMiddlewareRunner(&event)
|
mwRunner := newMiddlewareRunner(&event)
|
||||||
|
|
||||||
|
if !input.AuthInfo.IsReg() {
|
||||||
|
event.Status = "failed"
|
||||||
|
event.ErrInfo = pl.ErrorInfo{
|
||||||
|
Code: "auth-forbidden",
|
||||||
|
Detail: "user role is not allowed to create patient, only 'reg' position is allowed",
|
||||||
|
Raw: errors.New("authentication failed"),
|
||||||
|
}
|
||||||
|
return nil, pl.SetLogError(&event, input)
|
||||||
|
}
|
||||||
|
|
||||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||||
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
|
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
|
||||||
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user