dev: hotfix, cleaning + shortent code for auth
This commit is contained in:
No files matched your search
@@ -9,28 +9,28 @@ import (
|
|||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"simrs-vx/internal/domain/main-entities/intern"
|
|
||||||
eu "simrs-vx/internal/domain/main-entities/user"
|
|
||||||
|
|
||||||
pa "simrs-vx/internal/lib/auth"
|
|
||||||
el "simrs-vx/pkg/logger"
|
|
||||||
p "simrs-vx/pkg/password"
|
|
||||||
|
|
||||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
|
||||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
|
||||||
em "simrs-vx/internal/domain/main-entities/midwife"
|
|
||||||
en "simrs-vx/internal/domain/main-entities/nurse"
|
|
||||||
erc "simrs-vx/internal/domain/references/common"
|
|
||||||
erg "simrs-vx/internal/domain/references/organization"
|
|
||||||
|
|
||||||
a "github.com/karincake/apem"
|
a "github.com/karincake/apem"
|
||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
ms "github.com/karincake/apem/ms-redis"
|
ms "github.com/karincake/apem/ms-redis"
|
||||||
d "github.com/karincake/dodol"
|
d "github.com/karincake/dodol"
|
||||||
l "github.com/karincake/lepet"
|
l "github.com/karincake/lepet"
|
||||||
|
|
||||||
|
pa "simrs-vx/internal/lib/auth"
|
||||||
|
pl "simrs-vx/pkg/logger"
|
||||||
|
p "simrs-vx/pkg/password"
|
||||||
|
|
||||||
|
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||||
|
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||||
|
"simrs-vx/internal/domain/main-entities/intern"
|
||||||
|
em "simrs-vx/internal/domain/main-entities/midwife"
|
||||||
|
en "simrs-vx/internal/domain/main-entities/nurse"
|
||||||
|
eu "simrs-vx/internal/domain/main-entities/user"
|
||||||
|
erc "simrs-vx/internal/domain/references/common"
|
||||||
|
erg "simrs-vx/internal/domain/references/organization"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const source = "authentication"
|
||||||
|
|
||||||
var authCfg AuthCfg
|
var authCfg AuthCfg
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -40,13 +40,18 @@ func init() {
|
|||||||
// Generates token and store in redis at one place
|
// Generates token and store in redis at one place
|
||||||
// just return the error code
|
// just return the error code
|
||||||
func GenToken(input eu.LoginDto) (*d.Data, error) {
|
func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||||
|
event := pl.Event{
|
||||||
|
Feature: "Create",
|
||||||
|
Source: source,
|
||||||
|
}
|
||||||
|
|
||||||
// Get User
|
// Get User
|
||||||
user := &eu.User{Name: input.Name}
|
user := &eu.User{Name: input.Name}
|
||||||
// if input.Position_Code != "" {
|
// if input.Position_Code != "" {
|
||||||
// user.Position_Code = input.Position_Code
|
// user.Position_Code = input.Position_Code
|
||||||
// }
|
// }
|
||||||
if errCode := getAndCheck(user, user); errCode != "" {
|
if errCode := getAndCheck(user, user); errCode != "" {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: el.GenMessage(errCode)}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: pl.GenMessage(errCode)}}
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.LoginAttemptCount > 5 {
|
if user.LoginAttemptCount > 5 {
|
||||||
@@ -54,7 +59,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
lastAllowdLogin := user.LastAllowdLogin
|
lastAllowdLogin := user.LastAllowdLogin
|
||||||
if lastAllowdLogin.After(now.Add(-time.Hour * 1)) {
|
if lastAllowdLogin.After(now.Add(-time.Hour * 1)) {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: el.GenMessage("auth-login-tooMany")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: pl.GenMessage("auth-login-tooMany")}}
|
||||||
} else {
|
} else {
|
||||||
tn := time.Now()
|
tn := time.Now()
|
||||||
user.LastAllowdLogin = &tn
|
user.LastAllowdLogin = &tn
|
||||||
@@ -65,18 +70,18 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
tn := time.Now()
|
tn := time.Now()
|
||||||
user.LastAllowdLogin = &tn
|
user.LastAllowdLogin = &tn
|
||||||
dg.I.Save(&user)
|
dg.I.Save(&user)
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: el.GenMessage("auth-login-tooMany")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: pl.GenMessage("auth-login-tooMany")}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.Check(input.Password, user.Password) {
|
if !p.Check(input.Password, user.Password) {
|
||||||
user.LoginAttemptCount++
|
user.LoginAttemptCount++
|
||||||
dg.I.Save(&user)
|
dg.I.Save(&user)
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: el.GenMessage("auth-login-incorrect")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: pl.GenMessage("auth-login-incorrect")}}
|
||||||
} else if user.Status_Code == erc.USCBlocked {
|
} else if user.Status_Code == erc.USCBlocked {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: el.GenMessage("auth-login-blocked")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: pl.GenMessage("auth-login-blocked")}}
|
||||||
} else if user.Status_Code == erc.USCNew {
|
} else if user.Status_Code == erc.USCNew {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: el.GenMessage("auth-login-unverified")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: pl.GenMessage("auth-login-unverified")}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access token prep
|
// Access token prep
|
||||||
@@ -115,7 +120,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
employee := ee.Employee{}
|
employee := ee.Employee{}
|
||||||
dg.I.Where("\"User_Id\" = ?", user.Id).First(&employee)
|
dg.I.Where("\"User_Id\" = ?", user.Id).First(&employee)
|
||||||
if employee.Id == 0 {
|
if employee.Id == 0 {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: el.GenMessage("auth-noEmployee")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: pl.GenMessage("auth-noEmployee")}}
|
||||||
}
|
}
|
||||||
atClaims["employee_id"] = employee.Id
|
atClaims["employee_id"] = employee.Id
|
||||||
outputData["employee_id"] = employee.Id
|
outputData["employee_id"] = employee.Id
|
||||||
@@ -134,7 +139,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
doctor := ed.Doctor{}
|
doctor := ed.Doctor{}
|
||||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&doctor)
|
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&doctor)
|
||||||
if doctor.Id == 0 {
|
if doctor.Id == 0 {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: el.GenMessage("auth-noDoctor")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: pl.GenMessage("auth-noDoctor")}}
|
||||||
}
|
}
|
||||||
atClaims["doctor_code"] = doctor.Code
|
atClaims["doctor_code"] = doctor.Code
|
||||||
outputData["doctor_code"] = doctor.Code
|
outputData["doctor_code"] = doctor.Code
|
||||||
@@ -152,7 +157,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
empData := en.Nurse{}
|
empData := en.Nurse{}
|
||||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
||||||
if empData.Id == 0 {
|
if empData.Id == 0 {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: pl.GenMessage("auth-noNurse")}}
|
||||||
}
|
}
|
||||||
atClaims["nurse_code"] = empData.Code
|
atClaims["nurse_code"] = empData.Code
|
||||||
outputData["nurse_code"] = empData.Code
|
outputData["nurse_code"] = empData.Code
|
||||||
@@ -160,40 +165,40 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
empData := em.Midwife{}
|
empData := em.Midwife{}
|
||||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
||||||
if empData.Id == 0 {
|
if empData.Id == 0 {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: el.GenMessage("auth-noMidwife")}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: pl.GenMessage("auth-noMidwife")}}
|
||||||
}
|
}
|
||||||
atClaims["midwife_code"] = empData.Code
|
atClaims["midwife_code"] = empData.Code
|
||||||
outputData["midwife_code"] = empData.Code
|
outputData["midwife_code"] = empData.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}}
|
errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: pl.GenMessage("auth-getData-failed")}}
|
||||||
|
|
||||||
// division position
|
// division position
|
||||||
divisionPositions, err := getDivisionPosition(employee.Id)
|
divisionPositions, err := getDivisionPosition(employee.Id, &event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorGetPosition
|
return nil, errorGetPosition
|
||||||
}
|
}
|
||||||
|
|
||||||
// installation position
|
// installation position
|
||||||
installationPositions, err := getInstallationPosition(employee.Id)
|
installationPositions, err := getInstallationPosition(employee.Id, &event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorGetPosition
|
return nil, errorGetPosition
|
||||||
}
|
}
|
||||||
|
|
||||||
// unit position
|
// unit position
|
||||||
unitPositions, err := getUnitPosition(employee.Id)
|
unitPositions, err := getUnitPosition(employee.Id, &event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorGetPosition
|
return nil, errorGetPosition
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialist position
|
// specialist position
|
||||||
specialistPositions, err := getSpecialistPosition(employee.Id)
|
specialistPositions, err := getSpecialistPosition(employee.Id, &event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorGetPosition
|
return nil, errorGetPosition
|
||||||
}
|
}
|
||||||
|
|
||||||
// subspecialist position
|
// subspecialist position
|
||||||
subspecialistPositions, err := getSubspecialistPosition(employee.Id)
|
subspecialistPositions, err := getSubspecialistPosition(employee.Id, &event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorGetPosition
|
return nil, errorGetPosition
|
||||||
}
|
}
|
||||||
@@ -220,7 +225,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
at := jwt.NewWithClaims(jwt.SigningMethodHS256, atClaims)
|
at := jwt.NewWithClaims(jwt.SigningMethodHS256, atClaims)
|
||||||
ats, err := at.SignedString([]byte(atSecretKey))
|
ats, err := at.SignedString([]byte(atSecretKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: el.GenMessage("token-sign-err")}}
|
return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: pl.GenMessage("token-sign-err")}}
|
||||||
}
|
}
|
||||||
outputData["accessToken"] = ats
|
outputData["accessToken"] = ats
|
||||||
|
|
||||||
@@ -283,21 +288,21 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode
|
|||||||
func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) {
|
func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) {
|
||||||
token, errCode, errDetail := VerifyToken(r, tokenType)
|
token, errCode, errDetail := VerifyToken(r, tokenType)
|
||||||
if errCode != "" {
|
if errCode != "" {
|
||||||
return nil, d.FieldError{Code: errCode, Message: el.GenMessage(errCode, errDetail)}
|
return nil, d.FieldError{Code: errCode, Message: pl.GenMessage(errCode, errDetail)}
|
||||||
}
|
}
|
||||||
claims, ok := token.Claims.(jwt.MapClaims)
|
claims, ok := token.Claims.(jwt.MapClaims)
|
||||||
if ok && token.Valid {
|
if ok && token.Valid {
|
||||||
accessUuid, ok := claims["uuid"].(string)
|
accessUuid, ok := claims["uuid"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, d.FieldError{Code: "token-invalid", Message: el.GenMessage("token-invalid", "uuid not available")}
|
return nil, d.FieldError{Code: "token-invalid", Message: pl.GenMessage("token-invalid", "uuid not available")}
|
||||||
}
|
}
|
||||||
user_id, myErr := strconv.ParseInt(fmt.Sprintf("%.f", claims["user_id"]), 10, 64)
|
user_id, myErr := strconv.ParseInt(fmt.Sprintf("%.f", claims["user_id"]), 10, 64)
|
||||||
if myErr != nil {
|
if myErr != nil {
|
||||||
return nil, d.FieldError{Code: "token-invalid", Message: el.GenMessage("token-invalid", "uuid is not available")}
|
return nil, d.FieldError{Code: "token-invalid", Message: pl.GenMessage("token-invalid", "uuid is not available")}
|
||||||
}
|
}
|
||||||
accessUuidRedis := ms.I.Get(accessUuid)
|
accessUuidRedis := ms.I.Get(accessUuid)
|
||||||
if accessUuidRedis.String() == "" {
|
if accessUuidRedis.String() == "" {
|
||||||
return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")}
|
return nil, d.FieldError{Code: "token-unidentified", Message: pl.GenMessage("token-unidentified")}
|
||||||
}
|
}
|
||||||
|
|
||||||
data = &pa.AuthInfo{
|
data = &pa.AuthInfo{
|
||||||
@@ -324,41 +329,3 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
|
|||||||
func GetConfig() {
|
func GetConfig() {
|
||||||
a.ParseCfg(&authCfg)
|
a.ParseCfg(&authCfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkStrClaims(claim map[string]interface{}, key string) string {
|
|
||||||
if v, exist := claim[key]; exist && v != nil {
|
|
||||||
return v.(string)
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkStrPtrClaims(claim map[string]interface{}, key string) *string {
|
|
||||||
if v, exist := claim[key]; exist && v != nil {
|
|
||||||
val := v.(string)
|
|
||||||
return &val
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkIntClaims(claim map[string]interface{}, key string) int {
|
|
||||||
if v, exist := claim[key]; exist && v != nil {
|
|
||||||
return v.(int)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkIntPtrClaims(claim map[string]interface{}, key string) *int {
|
|
||||||
if v, exist := claim[key]; exist && v != nil {
|
|
||||||
val := int(v.(float64))
|
|
||||||
return &val
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkUntPtrClaims(claim map[string]interface{}, key string) *uint {
|
|
||||||
if v, exist := claim[key]; exist && v != nil {
|
|
||||||
val := uint(v.(float64))
|
|
||||||
return &val
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package authentication
|
package authentication
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
|
|
||||||
|
pl "simrs-vx/pkg/logger"
|
||||||
|
|
||||||
edp "simrs-vx/internal/domain/main-entities/division-position"
|
edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||||
eip "simrs-vx/internal/domain/main-entities/installation-position"
|
eip "simrs-vx/internal/domain/main-entities/installation-position"
|
||||||
esp "simrs-vx/internal/domain/main-entities/specialist-position"
|
esp "simrs-vx/internal/domain/main-entities/specialist-position"
|
||||||
@@ -12,8 +16,6 @@ import (
|
|||||||
usp "simrs-vx/internal/use-case/main-use-case/specialist-position"
|
usp "simrs-vx/internal/use-case/main-use-case/specialist-position"
|
||||||
ussp "simrs-vx/internal/use-case/main-use-case/subspecialist-position"
|
ussp "simrs-vx/internal/use-case/main-use-case/subspecialist-position"
|
||||||
uup "simrs-vx/internal/use-case/main-use-case/unit-position"
|
uup "simrs-vx/internal/use-case/main-use-case/unit-position"
|
||||||
|
|
||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// just return the error code
|
// just return the error code
|
||||||
@@ -28,43 +30,21 @@ func getAndCheck(input, condition any) (eCode string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDivisionPosition(employee_id uint) ([]string, error) {
|
func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) {
|
||||||
var result []string
|
var result []string
|
||||||
|
|
||||||
// var employee ee.Employee
|
|
||||||
// if err := dg.I.Where("\"Employee_Id\" = ?", employee_id).First(&employee).Error; err != nil {
|
|
||||||
// if err == gorm.ErrRecordNotFound {
|
|
||||||
// return result, nil
|
|
||||||
// }
|
|
||||||
// return result, errors.New("no employee found")
|
|
||||||
// }
|
|
||||||
|
|
||||||
//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
|
// get data division_position based on employee_id
|
||||||
dataDivisionPosition, err := udp.ReadList(edp.ReadListDto{
|
data, _, err := udp.ReadListData(edp.ReadListDto{
|
||||||
FilterDto: edp.FilterDto{Employee_Id: &employee_id},
|
FilterDto: edp.FilterDto{Employee_Id: &employee_id},
|
||||||
Includes: "division"})
|
Includes: "Division"}, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if list, ok := dataDivisionPosition.Data.([]edp.ResponseDto); ok {
|
if len(data) > 0 {
|
||||||
if len(list) > 0 {
|
for _, dp := range data {
|
||||||
for _, dp := range list {
|
if dp.Division != nil {
|
||||||
if dp.Division != nil {
|
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
|
||||||
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,23 +52,21 @@ func getDivisionPosition(employee_id uint) ([]string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInstallationPosition(employeeId uint) ([]string, error) {
|
func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||||
var result []string
|
var result []string
|
||||||
|
|
||||||
// get data unit_position based on employee_id
|
// get data unit_position based on employee_id
|
||||||
dataInstallationPosition, err := uip.ReadList(eip.ReadListDto{
|
data, _, err := uip.ReadListData(eip.ReadListDto{
|
||||||
FilterDto: eip.FilterDto{Employee_Id: &employeeId},
|
FilterDto: eip.FilterDto{Employee_Id: &employeeId},
|
||||||
Includes: "installation"})
|
Includes: "installation"}, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if list, ok := dataInstallationPosition.Data.([]eip.ResponseDto); ok {
|
if len(data) > 0 {
|
||||||
if len(list) > 0 {
|
for _, dp := range data {
|
||||||
for _, dp := range list {
|
if dp.Installation != nil {
|
||||||
if dp.Installation != nil {
|
result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code)
|
||||||
result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,23 +74,21 @@ func getInstallationPosition(employeeId uint) ([]string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUnitPosition(employeeId uint) ([]string, error) {
|
func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||||
var result []string
|
var result []string
|
||||||
|
|
||||||
// get data unit_position based on employee_id
|
// get data unit_position based on employee_id
|
||||||
dataUnitPosition, err := uup.ReadList(eup.ReadListDto{
|
data, _, err := uup.ReadListData(eup.ReadListDto{
|
||||||
FilterDto: eup.FilterDto{Employee_Id: &employeeId},
|
FilterDto: eup.FilterDto{Employee_Id: &employeeId},
|
||||||
Includes: "unit"})
|
Includes: "unit"}, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if list, ok := dataUnitPosition.Data.([]eup.ResponseDto); ok {
|
if len(data) > 0 {
|
||||||
if len(list) > 0 {
|
for _, dp := range data {
|
||||||
for _, dp := range list {
|
if dp.Unit != nil {
|
||||||
if dp.Unit != nil {
|
result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code)
|
||||||
result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,23 +96,21 @@ func getUnitPosition(employeeId uint) ([]string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSpecialistPosition(employeeId uint) ([]string, error) {
|
func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||||
var result []string
|
var result []string
|
||||||
|
|
||||||
// get data unit_position based on employee_id
|
// get data unit_position based on employee_id
|
||||||
dataSpecialistPosition, err := usp.ReadList(esp.ReadListDto{
|
data, _, err := usp.ReadListData(esp.ReadListDto{
|
||||||
FilterDto: esp.FilterDto{Employee_Id: &employeeId},
|
FilterDto: esp.FilterDto{Employee_Id: &employeeId},
|
||||||
Includes: "specialist"})
|
Includes: "specialist"}, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if list, ok := dataSpecialistPosition.Data.([]esp.ResponseDto); ok {
|
if len(data) > 0 {
|
||||||
if len(list) > 0 {
|
for _, dp := range data {
|
||||||
for _, dp := range list {
|
if dp.Specialist != nil {
|
||||||
if dp.Specialist != nil {
|
result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code)
|
||||||
result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,26 +118,47 @@ func getSpecialistPosition(employeeId uint) ([]string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSubspecialistPosition(employeeId uint) ([]string, error) {
|
func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||||
var result []string
|
var result []string
|
||||||
|
|
||||||
// get data unit_position based on employee_id
|
// get data unit_position based on employee_id
|
||||||
dataSubspecialistPosition, err := ussp.ReadList(essp.ReadListDto{
|
data, _, err := ussp.ReadListData(essp.ReadListDto{
|
||||||
FilterDto: essp.FilterDto{Employee_Id: &employeeId},
|
FilterDto: essp.FilterDto{Employee_Id: &employeeId},
|
||||||
Includes: "subspecialist"})
|
Includes: "subspecialist"}, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if list, ok := dataSubspecialistPosition.Data.([]essp.ResponseDto); ok {
|
if len(data) > 0 {
|
||||||
if len(list) > 0 {
|
for _, dp := range data {
|
||||||
for _, dp := range list {
|
if dp.Subspecialist != nil {
|
||||||
if dp.Subspecialist != nil {
|
result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code)
|
||||||
result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkStrClaims(claim map[string]interface{}, key string) string {
|
||||||
|
if v, exist := claim[key]; exist && v != nil {
|
||||||
|
return v.(string)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkStrPtrClaims(claim map[string]interface{}, key string) *string {
|
||||||
|
if v, exist := claim[key]; exist && v != nil {
|
||||||
|
val := v.(string)
|
||||||
|
return &val
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkUntPtrClaims(claim map[string]interface{}, key string) *uint {
|
||||||
|
if v, exist := claim[key]; exist && v != nil {
|
||||||
|
val := uint(v.(float64))
|
||||||
|
return &val
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user