Merge dev into feat/user
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
"time"
|
||||
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ep "simrs-vx/internal/domain/main-entities/person"
|
||||
epa "simrs-vx/internal/domain/main-entities/person-address"
|
||||
epc "simrs-vx/internal/domain/main-entities/person-contact"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
erg "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Name string `json:"name" validate:"maxLength=25"`
|
||||
Password string `json:"password" validate:"maxLength=255"`
|
||||
Status_Code erc.UserStatusCode `json:"status_code" validate:"maxLength=10"`
|
||||
ContractPosition_Code ero.ContractPositionCode `json:"contractPosition_code" validate:"maxLength=20"`
|
||||
Person_Id *uint `json:"-"`
|
||||
Person *ep.UpdateDto `json:"person"`
|
||||
PersonAddresses []epa.UpdateDto `json:"personAddresses"`
|
||||
@@ -28,6 +27,7 @@ type CreateDto struct {
|
||||
Infra_Id *uint16 `json:"infra_id"`
|
||||
Specialist_Id *uint16 `json:"specialist_id"`
|
||||
Subspecialist_Id *uint16 `json:"subspecialist_id"`
|
||||
ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -89,7 +89,7 @@ type EmployeUpdateDto struct {
|
||||
Person_Id *uint `json:"-"`
|
||||
Division_Code *string `json:"division_code"`
|
||||
Number *string `json:"number" validate:"maxLength=20"`
|
||||
Position_Code ero.EmployeePosisitionCode `json:"status_code" validate:"maxLength=10"`
|
||||
Position_Code erg.EmployeePosisitionCode `json:"status_code" validate:"maxLength=10"`
|
||||
Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"`
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,16 @@ import (
|
||||
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
erg "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Name string `json:"name" gorm:"unique;not null;size:25"`
|
||||
Password string `json:"password" gorm:"not null;size:255"`
|
||||
Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"`
|
||||
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
|
||||
// Position_Code ero.EmployeePosisitionCode `json:"position_code" gorm:"not null;size:20"`
|
||||
ContractPosition_Code ero.ContractPositionCode `json:"contractPosition_Code" gorm:"not null;size:20"`
|
||||
ecore.Main // adjust this according to the needs
|
||||
Name string `json:"name" gorm:"unique;not null;size:25"`
|
||||
Password string `json:"password" gorm:"not null;size:255"`
|
||||
Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"`
|
||||
ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20"`
|
||||
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
|
||||
LoginAttemptCount int `json:"-"`
|
||||
LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"`
|
||||
LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"`
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
package organization
|
||||
|
||||
type (
|
||||
UserPosisitionCode string
|
||||
ItemGroupCode string
|
||||
InfraGroupCode string
|
||||
UnitTypeCode string
|
||||
DoctorFeeTypeCode string
|
||||
ContractPositionCode string
|
||||
EmployeePosisitionCode string
|
||||
InternPosisitionCode string
|
||||
ItemGroupCode string
|
||||
InfraGroupCode string
|
||||
UnitTypeCode string
|
||||
DoctorFeeTypeCode string
|
||||
)
|
||||
|
||||
const (
|
||||
UPCReg UserPosisitionCode = "registration" // Admisi/Pendaftaran
|
||||
UPCNur UserPosisitionCode = "nurse" // Perawat
|
||||
UPCDoc UserPosisitionCode = "doctor" // Dokter
|
||||
UPCNut UserPosisitionCode = "nutritionist" // Ahli gizi
|
||||
UPCMwi UserPosisitionCode = "mid-wife" // Bidan
|
||||
UPCLab UserPosisitionCode = "laborant" // Laboran
|
||||
UPCPha UserPosisitionCode = "pharmacy" // Farmasi
|
||||
UPCPay UserPosisitionCode = "payment" // Pembayaran
|
||||
UPCHur UserPosisitionCode = "human-resource" // Sumber Daya Manusia
|
||||
UPCGea UserPosisitionCode = "general-affair" // Bagian Umum
|
||||
UPCInt UserPosisitionCode = "specialist-intern" // PPDS
|
||||
UPCMan UserPosisitionCode = "management" // Manajemen
|
||||
CSCEmp ContractPositionCode = "employee" // Pegawai
|
||||
CSCSpi ContractPositionCode = "intern" // PPDS
|
||||
|
||||
EPCReg EmployeePosisitionCode = "registration" // Admisi/Pendaftaran
|
||||
EPCNur EmployeePosisitionCode = "nurse" // Perawat
|
||||
EPCDoc EmployeePosisitionCode = "doctor" // Dokter
|
||||
EPCNut EmployeePosisitionCode = "nutritionist" // Ahli gizi
|
||||
EPCMwi EmployeePosisitionCode = "mid-wife" // Bidan
|
||||
EPCLab EmployeePosisitionCode = "laborant" // Laboran
|
||||
EPCPha EmployeePosisitionCode = "pharmacy" // Farmasi
|
||||
EPCPay EmployeePosisitionCode = "payment" // Pembayaran
|
||||
EPCHur EmployeePosisitionCode = "human-resource" // Sumber Daya Manusia
|
||||
EPCGea EmployeePosisitionCode = "general-affair" // Bagian Umum
|
||||
EPCMan EmployeePosisitionCode = "management" // Manajemen
|
||||
|
||||
IPCSpecialist = "specialist-intern"
|
||||
IPCNurse = "nurse-intern"
|
||||
|
||||
ITGCInfra ItemGroupCode = "infra"
|
||||
ITGCMedicine ItemGroupCode = "medicine"
|
||||
|
||||
@@ -11,12 +11,14 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
eu "simrs-vx/internal/domain/main-entities/user"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
pa "simrs-vx/pkg/auth-helper"
|
||||
el "simrs-vx/pkg/logger"
|
||||
p "simrs-vx/pkg/password"
|
||||
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
a "github.com/karincake/apem"
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
ms "github.com/karincake/apem/ms-redis"
|
||||
@@ -90,11 +92,26 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
atExpires := time.Now().Add(duration).Unix()
|
||||
atSecretKey := authCfg.AtSecretKey
|
||||
|
||||
// extra
|
||||
role := []string{}
|
||||
if user.ContractPosition_Code == "employee" {
|
||||
employee := ee.Employee{}
|
||||
dg.I.Where("user_id = ?", user.Id).First(&employee)
|
||||
role = append(role, "emp-"+string(*employee.Position_Code))
|
||||
} else if user.ContractPosition_Code == "intern" {
|
||||
// specialistIntern := esi.SpecialistIntern{}
|
||||
// dg.I.Where("user_id = ?", user.Id).First(&specialistIntern)
|
||||
role = append(role, "spi")
|
||||
}
|
||||
|
||||
// Creating Access Token
|
||||
atClaims := jwt.MapClaims{}
|
||||
atClaims["user_id"] = user.Id
|
||||
atClaims["user_name"] = user.Name
|
||||
atClaims["user_position_code"] = user.Position_Code
|
||||
// atClaims["user_email"] = user.Email
|
||||
// atClaims["user_position_code"] = user.Position_Code
|
||||
atClaims["user_employementStatus_code"] = user.ContractPosition_Code
|
||||
// atClaims["user_ref_id"] = user.Ref_Id
|
||||
atClaims["exp"] = atExpires
|
||||
atClaims["uuid"] = aUuid
|
||||
atClaims["user_division_positions"] = userDivisionPositions
|
||||
@@ -104,6 +121,15 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: el.GenMessage("token-sign-err")}}
|
||||
}
|
||||
|
||||
outputData := d.II{
|
||||
"user_id": strconv.Itoa(int(user.Id)),
|
||||
"user_name": user.Name,
|
||||
// "user_email": user.Email,
|
||||
"user_contractPosition_code": user.ContractPosition_Code,
|
||||
// "user_ref_id": user.Ref_Id,
|
||||
"accessToken": ats,
|
||||
}
|
||||
|
||||
// Save to redis
|
||||
now := time.Now()
|
||||
atx := time.Unix(atExpires, 0) //converting Unix to UTC(to Time object)
|
||||
@@ -125,13 +151,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
"structure": "single-data",
|
||||
"status": "verified",
|
||||
},
|
||||
Data: d.II{
|
||||
"user_id": strconv.Itoa(int(user.Id)),
|
||||
"user_name": user.Name,
|
||||
"user_position_code": user.Position_Code,
|
||||
"accessToken": ats,
|
||||
"user_division_positions": userDivisionPositions,
|
||||
},
|
||||
Data: outputData,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -186,41 +206,41 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
|
||||
return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")}
|
||||
}
|
||||
user_name := fmt.Sprintf("%v", claims["user_name"])
|
||||
// user_email := ""
|
||||
// if v, exist := claims["user_email"]; exist && v != nil {
|
||||
// user_email = v.(string)
|
||||
// }
|
||||
// ref_id := 0
|
||||
// if v, exist := claims["user_ref_id"]; exist && v != nil {
|
||||
// tmp := v.(float64)
|
||||
// ref_id = int(tmp)
|
||||
// }
|
||||
// position_code := ""
|
||||
// if v, exist := claims["user_position_code"]; exist && v != nil {
|
||||
// position_code = v.(string)
|
||||
// }
|
||||
// data = &AuthInfo{
|
||||
// Uuid: accessUuid,
|
||||
// User_Id: int(user_id),
|
||||
// User_Name: user_name,
|
||||
// User_Email: user_email,
|
||||
// User_Ref_Id: ref_id,
|
||||
// User_Position_Code: position_code,
|
||||
contractPosition_code := ""
|
||||
if v, exist := claims["contractPosition_code"]; exist && v != nil {
|
||||
contractPosition_code = v.(string)
|
||||
}
|
||||
employee_position_code := ""
|
||||
if v, exist := claims["employee_position_code"]; exist && v != nil {
|
||||
employee_position_code = v.(string)
|
||||
}
|
||||
|
||||
var userDivisionPositions []pa.DivisionPosition
|
||||
raw := claims["user_division_positions"]
|
||||
if raw == nil {
|
||||
fmt.Println("No user_division_positions found in claims")
|
||||
} else {
|
||||
list, ok := raw.([]interface{})
|
||||
if !ok {
|
||||
fmt.Printf("user_division_positions is not []interface{}, but %T\n", raw)
|
||||
} else {
|
||||
fmt.Printf("Found %d division positions\n", len(list))
|
||||
for i, item := range list {
|
||||
if m, ok := item.(map[string]interface{}); ok {
|
||||
fmt.Printf("Item %d: %v\n", i, m)
|
||||
dp := pa.DivisionPosition{
|
||||
Division_Code: fmt.Sprintf("%v", m["division_code"]),
|
||||
DivisionPosition_Code: fmt.Sprintf("%v", m["divisionPosition_code"]),
|
||||
}
|
||||
userDivisionPositions = append(userDivisionPositions, dp)
|
||||
} else {
|
||||
fmt.Printf("Item %d not map[string]interface{} but %T\n", i, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
position_code := ""
|
||||
if v, exist := claims["user_position_code"]; exist && v != nil {
|
||||
position_code = v.(string)
|
||||
}
|
||||
data = &pa.AuthInfo{
|
||||
Uuid: accessUuid,
|
||||
User_Id: uint(user_id),
|
||||
User_Name: user_name,
|
||||
User_Position_Code: position_code,
|
||||
User_DivisionPositions: userDivisionPositions,
|
||||
Uuid: accessUuid,
|
||||
User_Id: uint(user_id),
|
||||
User_Name: user_name,
|
||||
User_ContractPosition_code: contractPosition_code,
|
||||
Employee_Position_Code: &employee_position_code,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
es "simrs-vx/internal/domain/main-entities/soapi"
|
||||
"gorm.io/gorm"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
edo "simrs-vx/internal/domain/main-entities/device-order"
|
||||
emo "simrs-vx/internal/domain/main-entities/material-order"
|
||||
@@ -23,6 +25,7 @@ import (
|
||||
epi "simrs-vx/internal/domain/main-entities/prescription-item"
|
||||
|
||||
// udo "simrs-vx/internal/use-case/main-use-case/device-order"
|
||||
es "simrs-vx/internal/domain/main-entities/soapi"
|
||||
um "simrs-vx/internal/use-case/main-use-case/medication"
|
||||
umei "simrs-vx/internal/use-case/main-use-case/medication-item"
|
||||
umi "simrs-vx/internal/use-case/main-use-case/medicine-mix"
|
||||
@@ -30,13 +33,9 @@ import (
|
||||
up "simrs-vx/internal/use-case/main-use-case/prescription"
|
||||
upi "simrs-vx/internal/use-case/main-use-case/prescription-item"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
|
||||
@@ -114,7 +113,7 @@ func checkSoapiByDocExists(encounter_id uint, event *pl.Event, tx *gorm.DB) erro
|
||||
}
|
||||
|
||||
for _, s := range soapies {
|
||||
if s.Employee != nil && s.Employee.User != nil && s.Employee.User.Position_Code == ero.UPCDoc {
|
||||
if s.Employee != nil && s.Employee.User != nil && *s.Employee.Position_Code == ero.EPCDoc {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
el "simrs-vx/internal/domain/main-entities/laborant"
|
||||
em "simrs-vx/internal/domain/main-entities/midwife"
|
||||
en "simrs-vx/internal/domain/main-entities/nurse"
|
||||
et "simrs-vx/internal/domain/main-entities/nutritionist"
|
||||
ep "simrs-vx/internal/domain/main-entities/pharmacist"
|
||||
@@ -19,7 +18,6 @@ import (
|
||||
ud "simrs-vx/internal/use-case/main-use-case/doctor"
|
||||
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
||||
ul "simrs-vx/internal/use-case/main-use-case/laborant"
|
||||
um "simrs-vx/internal/use-case/main-use-case/midwife"
|
||||
un "simrs-vx/internal/use-case/main-use-case/nurse"
|
||||
ut "simrs-vx/internal/use-case/main-use-case/nutritionist"
|
||||
upe "simrs-vx/internal/use-case/main-use-case/person"
|
||||
@@ -85,7 +83,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
data = *resData
|
||||
}
|
||||
|
||||
if input.Position_Code == ero.UPCInt {
|
||||
if input.ContractPosition_Code == ero.CSCSpi {
|
||||
createInt := esi.CreateDto{
|
||||
Person_Id: input.Person_Id,
|
||||
Specialist_Id: input.Specialist_Id,
|
||||
@@ -105,8 +103,8 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
switch input.Position_Code {
|
||||
case ero.UPCDoc:
|
||||
switch input.Employee.Position_Code {
|
||||
case ero.EPCDoc:
|
||||
createDoc := ed.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
@@ -118,7 +116,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
if _, err := ud.CreateData(createDoc, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCNur:
|
||||
case ero.EPCNur:
|
||||
createNurse := en.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
@@ -128,7 +126,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
if _, err := un.CreateData(createNurse, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCNut:
|
||||
case ero.EPCNut:
|
||||
createNutritionist := et.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
@@ -136,7 +134,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
if _, err := ut.CreateData(createNutritionist, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCPha:
|
||||
case ero.EPCPha:
|
||||
createPharmacist := ep.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
@@ -144,7 +142,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
if _, err := up.CreateData(createPharmacist, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCLab:
|
||||
case ero.EPCLab:
|
||||
createLaborant := el.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
@@ -152,16 +150,6 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
if _, err := ul.CreateData(createLaborant, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCMwi:
|
||||
createMidwife := em.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
}
|
||||
if _, err := um.CreateData(em.CreateDto(createMidwife), &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCReg, ero.UPCHur, ero.UPCGea, ero.UPCMan:
|
||||
// do nothing
|
||||
default:
|
||||
return errors.New("invalid employee position")
|
||||
}
|
||||
@@ -317,7 +305,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
person_id, err := getPersonIdByUserId(data.Id, input.Position_Code, &event, tx)
|
||||
person_id, err := getPersonIdByUserId(data.Id, input.ContractPosition_Code, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
@@ -348,7 +336,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if input.Position_Code == ero.UPCInt {
|
||||
if input.ContractPosition_Code == ero.CSCSpi {
|
||||
readInt := esi.ReadDetailDto{User_Id: &data.Id}
|
||||
readIntData, err := usi.ReadDetailData(readInt, &event, tx)
|
||||
if err != nil {
|
||||
@@ -384,8 +372,8 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
switch input.Position_Code {
|
||||
case ero.UPCDoc:
|
||||
switch input.Employee.Position_Code {
|
||||
case ero.EPCDoc:
|
||||
readDoc := ed.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||
readDocData, err := ud.ReadDetailData(readDoc, &event, tx)
|
||||
if err != nil {
|
||||
@@ -407,7 +395,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
if _, err := ud.CreateData(createDoc, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCNur:
|
||||
case ero.EPCNur:
|
||||
readNur := en.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||
readNurData, err := un.ReadDetailData(readNur, &event, tx)
|
||||
if err != nil {
|
||||
@@ -427,7 +415,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
if _, err := un.CreateData(createNur, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCNut:
|
||||
case ero.EPCNut:
|
||||
readNut := et.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||
readNutData, err := ut.ReadDetailData(readNut, &event, tx)
|
||||
if err != nil {
|
||||
@@ -447,7 +435,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
if _, err := ut.CreateData(createNut, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCPha:
|
||||
case ero.EPCPha:
|
||||
readPha := ep.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||
readPhaData, err := up.ReadDetailData(readPha, &event, tx)
|
||||
if err != nil {
|
||||
@@ -467,7 +455,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
if _, err := up.CreateData(createPha, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCLab:
|
||||
case ero.EPCLab:
|
||||
readLab := el.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||
readLabData, err := ul.ReadDetailData(readLab, &event, tx)
|
||||
if err != nil {
|
||||
@@ -487,28 +475,6 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
if _, err := ul.CreateData(createLab, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCMwi:
|
||||
readMidwife := em.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||
readMidwifeData, err := um.ReadDetailData(readMidwife, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
createMidwife := em.CreateDto{
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
}
|
||||
if readMidwifeData != nil {
|
||||
if err := um.UpdateData(em.UpdateDto{CreateDto: createMidwife}, readMidwifeData, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := um.CreateData(createMidwife, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
case ero.UPCReg, ero.UPCHur, ero.UPCGea, ero.UPCMan:
|
||||
// do nothing
|
||||
default:
|
||||
return errors.New("invalid employee position")
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
esi "simrs-vx/internal/domain/main-entities/specialist-intern"
|
||||
e "simrs-vx/internal/domain/main-entities/user"
|
||||
|
||||
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
||||
usi "simrs-vx/internal/use-case/main-use-case/specialist-intern"
|
||||
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
"gorm.io/gorm"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
p "simrs-vx/pkg/password"
|
||||
|
||||
"gorm.io/gorm"
|
||||
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
||||
usi "simrs-vx/internal/use-case/main-use-case/specialist-intern"
|
||||
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
esi "simrs-vx/internal/domain/main-entities/specialist-intern"
|
||||
e "simrs-vx/internal/domain/main-entities/user"
|
||||
erg "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
func setCreate(src e.CreateDto, dst *e.User) error {
|
||||
@@ -30,15 +30,14 @@ func setCreate(src e.CreateDto, dst *e.User) error {
|
||||
dst.Name = src.Name
|
||||
dst.Password = pass
|
||||
dst.Status_Code = src.Status_Code
|
||||
dst.Position_Code = src.Position_Code
|
||||
dst.ContractPosition_Code = src.ContractPosition_Code
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setUpdate(src e.UpdateDto, dst *e.User) {
|
||||
dst.Status_Code = src.Status_Code
|
||||
dst.Position_Code = src.Position_Code
|
||||
|
||||
dst.ContractPosition_Code = src.ContractPosition_Code
|
||||
}
|
||||
|
||||
func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
||||
@@ -54,9 +53,10 @@ func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
||||
}
|
||||
}
|
||||
|
||||
func getPersonIdByUserId(userId uint, positionCode ero.UserPosisitionCode, event *pl.Event, tx *gorm.DB) (*uint, error) {
|
||||
func getPersonIdByUserId(userId uint, positionCode erg.ContractPositionCode, event *pl.Event, tx *gorm.DB) (*uint, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "DBGetPersonIdByUserId")
|
||||
if positionCode == ero.UPCInt {
|
||||
if positionCode == erg.CSCEmp {
|
||||
} else if positionCode == erg.CSCSpi {
|
||||
specInt, err := usi.ReadDetailData(esi.ReadDetailDto{User_Id: &userId}, event, tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+48
-13
@@ -7,11 +7,15 @@ import (
|
||||
type AuthKey struct{}
|
||||
|
||||
type AuthInfo struct {
|
||||
Uuid string
|
||||
User_Id uint
|
||||
User_Name string
|
||||
User_DivisionPositions []DivisionPosition
|
||||
User_Position_Code string
|
||||
Uuid string
|
||||
User_Id uint
|
||||
User_Name string
|
||||
User_ContractPosition_code string
|
||||
Employee_Position_Code *string
|
||||
Intern_Position_Code *string
|
||||
User_DivisionPositions []DivisionPosition
|
||||
// User_DivisionPositions []DivisionPosition
|
||||
// User_Position_Code string
|
||||
}
|
||||
|
||||
type DivisionPosition struct {
|
||||
@@ -20,33 +24,64 @@ type DivisionPosition struct {
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsDoctor() bool {
|
||||
return a.User_Position_Code == string(ero.UPCDoc)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCDoc)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsNurse() bool {
|
||||
return a.User_Position_Code == string(ero.UPCNur)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCNur)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsNutritionist() bool {
|
||||
return a.User_Position_Code == string(ero.UPCNut)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCNut)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsLaborant() bool {
|
||||
return a.User_Position_Code == string(ero.UPCLab)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCLab)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsPharmacist() bool {
|
||||
return a.User_Position_Code == string(ero.UPCPha)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCPha)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsPayment() bool {
|
||||
return a.User_Position_Code == string(ero.UPCPay)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCPay)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsManagement() bool {
|
||||
return a.User_Position_Code == string(ero.UPCMan)
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCMan)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsSpecialistIntern() bool {
|
||||
return a.User_Position_Code == string(ero.UPCInt)
|
||||
if a.Intern_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Intern_Position_Code == string(ero.IPCSpecialist)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsNurseIntern() bool {
|
||||
if a.Intern_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Intern_Position_Code == string(ero.IPCNurse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user