2c432a7bef
+ moved pkg/auth-helper to internal/lib/auth + update AuthInfo + cleaning
170 lines
4.3 KiB
Go
170 lines
4.3 KiB
Go
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"
|
|
)
|
|
|
|
// 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) ([]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{
|
|
FilterDto: edp.FilterDto{Employee_Id: &employee_id},
|
|
Includes: "division"})
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|