165 lines
4.0 KiB
Go
165 lines
4.0 KiB
Go
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"
|
|
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"
|
|
)
|
|
|
|
// just return the error code
|
|
func getAndCheck(input, condition any) (eCode string) {
|
|
result := dg.I.Where(condition).Find(&input)
|
|
if result.Error != nil {
|
|
return "fetch-fail"
|
|
} else if result.RowsAffected == 0 {
|
|
return "auth-login-incorrect"
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) {
|
|
var result []string
|
|
|
|
// get data division_position based on employee_id
|
|
data, _, err := udp.ReadListData(edp.ReadListDto{
|
|
FilterDto: edp.FilterDto{Employee_Id: &employee_id},
|
|
Includes: "Division"}, event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(data) > 0 {
|
|
for _, dp := range data {
|
|
if dp.Division != nil {
|
|
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
|
|
}
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
|
var result []string
|
|
|
|
// get data unit_position based on employee_id
|
|
data, _, err := uip.ReadListData(eip.ReadListDto{
|
|
FilterDto: eip.FilterDto{Employee_Id: &employeeId},
|
|
Includes: "installation"}, event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(data) > 0 {
|
|
for _, dp := range data {
|
|
if dp.Installation != nil {
|
|
result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code)
|
|
}
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
|
var result []string
|
|
|
|
// get data unit_position based on employee_id
|
|
data, _, err := uup.ReadListData(eup.ReadListDto{
|
|
FilterDto: eup.FilterDto{Employee_Id: &employeeId},
|
|
Includes: "unit"}, event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(data) > 0 {
|
|
for _, dp := range data {
|
|
if dp.Unit != nil {
|
|
result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code)
|
|
}
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
|
var result []string
|
|
|
|
// get data unit_position based on employee_id
|
|
data, _, err := usp.ReadListData(esp.ReadListDto{
|
|
FilterDto: esp.FilterDto{Employee_Id: &employeeId},
|
|
Includes: "specialist"}, event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(data) > 0 {
|
|
for _, dp := range data {
|
|
if dp.Specialist != nil {
|
|
result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code)
|
|
}
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
|
var result []string
|
|
|
|
// get data unit_position based on employee_id
|
|
data, _, err := ussp.ReadListData(essp.ReadListDto{
|
|
FilterDto: essp.FilterDto{Employee_Id: &employeeId},
|
|
Includes: "subspecialist"}, event)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
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
|
|
}
|