material, device-order required doctor_id, infra search and parent,childrens
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/material-order"
|
||||
|
||||
ud "simrs-vx/internal/use-case/main-use-case/doctor"
|
||||
ue "simrs-vx/internal/use-case/main-use-case/encounter"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
@@ -45,6 +46,22 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
return errors.New("encounter is already done")
|
||||
}
|
||||
|
||||
if !input.AuthInfo.IsDoctor() {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "auth-forbidden",
|
||||
Detail: "user position is not allowed",
|
||||
Raw: errors.New("authentication failed"),
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input.Doctor_Id = doctor_id
|
||||
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
@@ -208,6 +225,33 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if !input.AuthInfo.IsDoctor() {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "auth-forbidden",
|
||||
Detail: "user position is not allowed",
|
||||
Raw: errors.New("authentication failed"),
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !data.IsSameDoctor(doctor_id) {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "auth-forbidden",
|
||||
Detail: "doctor is not the same as the data",
|
||||
Raw: errors.New("authentication failed"),
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
input.Doctor_Id = doctor_id
|
||||
|
||||
if err := UpdateData(input, data, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MaterialOrder) {
|
||||
|
||||
data.Encounter_Id = inputSrc.Encounter_Id
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
data.Doctor_Id = inputSrc.Doctor_Id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user