dev: hotfix, cleaning + shortent code for auth
This commit is contained in:
No files matched your search
@@ -1,6 +1,10 @@
|
||||
package authentication
|
||||
|
||||
import (
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
|
||||
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"
|
||||
@@ -12,8 +16,6 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
// just return the error code
|
||||
@@ -28,43 +30,21 @@ func getAndCheck(input, condition any) (eCode string) {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getDivisionPosition(employee_id uint) ([]string, error) {
|
||||
func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) {
|
||||
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
|
||||
dataDivisionPosition, err := udp.ReadList(edp.ReadListDto{
|
||||
data, _, err := udp.ReadListData(edp.ReadListDto{
|
||||
FilterDto: edp.FilterDto{Employee_Id: &employee_id},
|
||||
Includes: "division"})
|
||||
Includes: "Division"}, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
if len(data) > 0 {
|
||||
for _, dp := range data {
|
||||
if dp.Division != nil {
|
||||
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,23 +52,21 @@ func getDivisionPosition(employee_id uint) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getInstallationPosition(employeeId uint) ([]string, error) {
|
||||
func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// 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},
|
||||
Includes: "installation"})
|
||||
Includes: "installation"}, event)
|
||||
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)
|
||||
}
|
||||
if len(data) > 0 {
|
||||
for _, dp := range data {
|
||||
if dp.Installation != nil {
|
||||
result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,23 +74,21 @@ func getInstallationPosition(employeeId uint) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getUnitPosition(employeeId uint) ([]string, error) {
|
||||
func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// 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},
|
||||
Includes: "unit"})
|
||||
Includes: "unit"}, event)
|
||||
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)
|
||||
}
|
||||
if len(data) > 0 {
|
||||
for _, dp := range data {
|
||||
if dp.Unit != nil {
|
||||
result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,23 +96,21 @@ func getUnitPosition(employeeId uint) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getSpecialistPosition(employeeId uint) ([]string, error) {
|
||||
func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// 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},
|
||||
Includes: "specialist"})
|
||||
Includes: "specialist"}, event)
|
||||
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)
|
||||
}
|
||||
if len(data) > 0 {
|
||||
for _, dp := range data {
|
||||
if dp.Specialist != nil {
|
||||
result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,26 +118,47 @@ func getSpecialistPosition(employeeId uint) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getSubspecialistPosition(employeeId uint) ([]string, error) {
|
||||
func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// 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},
|
||||
Includes: "subspecialist"})
|
||||
Includes: "subspecialist"}, event)
|
||||
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)
|
||||
}
|
||||
if len(data) > 0 {
|
||||
for _, dp := range data {
|
||||
if dp.Subspecialist != nil {
|
||||
result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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