adjustment auth token with position
This commit is contained in:
@@ -155,12 +155,44 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
atClaims["nurse_id"] = nurse.Id
|
||||
outputData["nurse_id"] = nurse.Id
|
||||
}
|
||||
|
||||
errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}}
|
||||
|
||||
// division position
|
||||
divsionPositions, err := getDivisionPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}}
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// installation position
|
||||
installationPositions, err := getInstallationPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// unit position
|
||||
unitPositions, err := getUnitPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// specialist position
|
||||
specialistPositions, err := getSpecialistPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// subspecialist position
|
||||
subspecialistPositions, err := getSubspecialistPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
role = append(role, divsionPositions...)
|
||||
role = append(role, installationPositions...)
|
||||
role = append(role, unitPositions...)
|
||||
role = append(role, specialistPositions...)
|
||||
role = append(role, subspecialistPositions...)
|
||||
// atClaims["division_positions"] = divsionPositions
|
||||
// outputData["division_positions"] = divsionPositions
|
||||
}
|
||||
|
||||
@@ -2,9 +2,18 @@ package authentication
|
||||
|
||||
import (
|
||||
edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||
eip "simrs-vx/internal/domain/main-entities/installation-position"
|
||||
esp "simrs-vx/internal/domain/main-entities/specialist-position"
|
||||
essp "simrs-vx/internal/domain/main-entities/subspecialist-position"
|
||||
eup "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
|
||||
udp "simrs-vx/internal/use-case/main-use-case/division-position"
|
||||
uip "simrs-vx/internal/use-case/main-use-case/installation-position"
|
||||
usp "simrs-vx/internal/use-case/main-use-case/specialist-position"
|
||||
ussp "simrs-vx/internal/use-case/main-use-case/subspecialist-position"
|
||||
uup "simrs-vx/internal/use-case/main-use-case/unit-position"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// just return the error code
|
||||
@@ -34,21 +43,129 @@ func getDivisionPosition(employee_id uint) ([]string, error) {
|
||||
// return result, errors.New("no employee found")
|
||||
// }
|
||||
|
||||
var divisionPositions []edp.DivisionPosition
|
||||
err := dg.I.
|
||||
Preload("Division").
|
||||
Where("\"Employee_Id\" = ?", employee_id).
|
||||
Find(&divisionPositions).Error
|
||||
//var divisionPositions []edp.DivisionPosition
|
||||
//err := dg.I.
|
||||
// Preload("Division").
|
||||
// Where("\"Employee_Id\" = ?", employee_id).
|
||||
// Find(&divisionPositions).Error
|
||||
//if err != nil {
|
||||
// if err == gorm.ErrRecordNotFound {
|
||||
// return result, nil
|
||||
// }
|
||||
// return result, err
|
||||
//}
|
||||
|
||||
// get data division_position based on employee_id
|
||||
dataDivisionPosition, err := udp.ReadList(edp.ReadListDto{
|
||||
FilterDto: edp.FilterDto{Employee_Id: &employee_id},
|
||||
Includes: "division"})
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return result, nil
|
||||
}
|
||||
return result, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, dp := range divisionPositions {
|
||||
if dp.Division != nil {
|
||||
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
|
||||
if list, ok := dataDivisionPosition.Data.([]edp.ResponseDto); ok {
|
||||
if len(list) > 0 {
|
||||
for _, dp := range list {
|
||||
if dp.Division != nil {
|
||||
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getInstallationPosition(employeeId uint) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
dataInstallationPosition, err := uip.ReadList(eip.ReadListDto{
|
||||
FilterDto: eip.FilterDto{Employee_Id: &employeeId},
|
||||
Includes: "installation"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if list, ok := dataInstallationPosition.Data.([]eip.ResponseDto); ok {
|
||||
if len(list) > 0 {
|
||||
for _, dp := range list {
|
||||
if dp.Installation != nil {
|
||||
result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getUnitPosition(employeeId uint) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
dataUnitPosition, err := uup.ReadList(eup.ReadListDto{
|
||||
FilterDto: eup.FilterDto{Employee_Id: &employeeId},
|
||||
Includes: "unit"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if list, ok := dataUnitPosition.Data.([]eup.ResponseDto); ok {
|
||||
if len(list) > 0 {
|
||||
for _, dp := range list {
|
||||
if dp.Unit != nil {
|
||||
result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getSpecialistPosition(employeeId uint) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
dataSpecialistPosition, err := usp.ReadList(esp.ReadListDto{
|
||||
FilterDto: esp.FilterDto{Employee_Id: &employeeId},
|
||||
Includes: "specialist"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if list, ok := dataSpecialistPosition.Data.([]esp.ResponseDto); ok {
|
||||
if len(list) > 0 {
|
||||
for _, dp := range list {
|
||||
if dp.Specialist != nil {
|
||||
result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getSubspecialistPosition(employeeId uint) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
dataSubspecialistPosition, err := ussp.ReadList(essp.ReadListDto{
|
||||
FilterDto: essp.FilterDto{Employee_Id: &employeeId},
|
||||
Includes: "subspecialist"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if list, ok := dataSubspecialistPosition.Data.([]essp.ResponseDto); ok {
|
||||
if len(list) > 0 {
|
||||
for _, dp := range list {
|
||||
if dp.Subspecialist != nil {
|
||||
result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user