Files
simrsx-be/internal/use-case/main-use-case/authentication/helper.go
T

57 lines
1.2 KiB
Go

package authentication
import (
edp "simrs-vx/internal/domain/main-entities/division-position"
dg "github.com/karincake/apem/db-gorm-pg"
"gorm.io/gorm"
)
// 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 getDocName(id uint) string {
return "authentication"
}
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
}
for _, dp := range divisionPositions {
if dp.Division != nil {
result = append(result, "div-"+dp.Division.Code+"-"+dp.Code)
}
}
return result, nil
}