remove unnecessary field in readdetail
This commit is contained in:
@@ -28,12 +28,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Uom_Code string `json:"uom_code"`
|
||||
Infra_Id *uint16 `json:"infra_id"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -21,10 +21,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
IndName string `json:"indName"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -19,10 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint32 `json:"id"`
|
||||
Regency_Code string `json:"regency_code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint32 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -22,10 +22,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Division_Id *uint16 `json:"division_id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -21,10 +21,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Parent_Id *int16 `json:"parent_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -26,11 +26,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Doctor_Id *uint `json:"doctor_id"`
|
||||
FeeType_Code *ero.DoctorFeeTypeCode `json:"feeType_code"`
|
||||
Price *float64 `json:"price"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Doctor_Id *uint `json:"doctor_id"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -29,7 +29,6 @@ type ReadDetailDto struct {
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
IHS_Number *string `json:"ihs_number"`
|
||||
SIP_Number *string `json:"sip_number"`
|
||||
Unit_Id *uint `json:"unit_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package employee
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ed "simrs-vx/internal/domain/main-entities/division"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type Employee struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
User_Id *uint `json:"user_id"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
Position_Code ero.EmployeePosisitionCode `json:"position_code" gorm:"not null;size:20"`
|
||||
Division_Code *string `json:"division_code"`
|
||||
Division *ed.Division `json:"division,omitempty" gorm:"foreignKey:Division_Code;references:Code"`
|
||||
Number *string `json:"number" gorm:"size:20"`
|
||||
Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"`
|
||||
}
|
||||
@@ -3,13 +3,17 @@ package employee
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ed "simrs-vx/internal/domain/main-entities/division"
|
||||
ep "simrs-vx/internal/domain/main-entities/person"
|
||||
eu "simrs-vx/internal/domain/main-entities/user"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
User_Id *uint `json:"user_id"`
|
||||
UserRequest *eu.CreateDto `json:"user_request"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
PersonRequest *ep.CreateDto `json:"person_request"`
|
||||
Position_Code ero.EmployeePosisitionCode `json:"position_code"`
|
||||
Division_Code *string `json:"division_code"`
|
||||
Number *string `json:"number"`
|
||||
@@ -17,6 +21,12 @@ type CreateDto struct {
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
FilterDto
|
||||
Includes string `json:"includes"`
|
||||
Preloads []string `json:"-"`
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
User_Id *uint `json:"user_id"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
Position_Code ero.EmployeePosisitionCode `json:"position_code"`
|
||||
@@ -30,13 +40,10 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
User_Id *uint `json:"user_id"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
Position_Code ero.EmployeePosisitionCode `json:"position_code"`
|
||||
Division_Code *string `json:"division_code"`
|
||||
Number *string `json:"number"`
|
||||
Status_Code erc.ActiveStatusCode `json:"status_code"`
|
||||
Id uint16 `json:"id"`
|
||||
User_Id *uint `json:"user_id"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
Number *string `json:"number"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
@@ -86,3 +93,9 @@ func ToResponseList(data []Employee) []ResponseDto {
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func (c CreateDto) Sanitize() CreateDto {
|
||||
sanitized := c
|
||||
sanitized.UserRequest.Password = "[REDACTED]"
|
||||
return sanitized
|
||||
}
|
||||
|
||||
@@ -19,9 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -28,12 +28,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code"`
|
||||
Parent_Id *uint16 `json:"parent_id"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -22,10 +22,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -26,12 +26,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Regency_Code *string `json:"regency_code"`
|
||||
Address string `json:"address"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
PhoneNumber *string `json:"phoneNumber"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -23,10 +23,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Price float64 `json:"price"`
|
||||
InsuranceCompany_Code *string `json:"insuranceCompany_code"`
|
||||
Id uint16 `json:"id"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -29,13 +29,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code"`
|
||||
Uom_Code *string `json:"uom_code"`
|
||||
Infra_Id *int16 `json:"infra_id"`
|
||||
Stock *int `json:"stock"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -30,13 +30,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Uom_Code string `json:"uom_code"`
|
||||
Infra_Id *uint16 `json:"infra_id"`
|
||||
Stock *int `json:"stock"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -22,10 +22,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Scope_Code *ere.CheckupScopeCode `json:"scope_code"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -21,10 +21,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
CheckupCategory_Code *string `json:"checkupCategory_code"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -24,10 +24,7 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"`
|
||||
ProcedureSrc_Id *uint `json:"procedureSrc_id"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -22,10 +22,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -19,9 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -19,9 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -23,10 +23,7 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
MedicineMix_Id *uint `json:"medicineMix_id"`
|
||||
Medicine_Id *uint `json:"medicine_id"`
|
||||
Dose *uint8 `json:"dose"`
|
||||
Id uint16 `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -17,8 +17,7 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -38,16 +38,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
MedicineGroup_Code *string `json:"medicineGroup_code"`
|
||||
MedicineMethod_Code *string `json:"medicineMethod_code"`
|
||||
Uom_Code *string `json:"uom_code"`
|
||||
Dose uint8 `json:"dose"`
|
||||
Infra_Id *uint16 `json:"infra_id"`
|
||||
Stock *int `json:"stock"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
Item_Id *uint `json:"item_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -19,12 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint `json:"id"`
|
||||
Person_Id uint `json:"person_id"`
|
||||
Address string `json:"address"`
|
||||
Rt string `json:"rt"`
|
||||
Rw string `json:"rw"`
|
||||
Village_Code string `json:"village_code"`
|
||||
Id uint `json:"id"`
|
||||
Person_Id uint `json:"person_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -18,10 +18,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint `json:"id"`
|
||||
Person_Id uint `json:"person_id"`
|
||||
Type_Code erp.ContactTypeCode `json:"type_code"`
|
||||
Value string `json:"value"`
|
||||
Id uint `json:"id"`
|
||||
Person_Id uint `json:"person_id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -29,17 +29,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
BirthDate *time.Time `json:"birthDate,omitempty"`
|
||||
BirthRegency_Code *string `json:"birthRegency_code"`
|
||||
Gender_Code *erp.GenderCode `json:"gender_code"`
|
||||
ResidentIdentityNumber *string `json:"residentIdentityNumber"`
|
||||
Religion_Code *erp.ReligionCode `json:"religion_code"`
|
||||
Education_Code *erp.EducationCode `json:"education_code"`
|
||||
Ocupation_Code *erp.OcupationCode `json:"occupation_code"`
|
||||
Ocupation_Name *string `json:"occupation_name"`
|
||||
Ethnic_Code *string `json:"ethnic_code"`
|
||||
Id uint `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
ResidentIdentityNumber *string `json:"residentIdentityNumber"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -21,10 +21,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Regency_Code string `json:"regency_code"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -26,12 +26,7 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Doctor_Id *uint `json:"doctor_id"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime"`
|
||||
EndTime *string `json:"endTime"`
|
||||
Id uint16 `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -21,10 +21,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
IndName string `json:"indName"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -15,9 +15,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id int16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id int16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -19,10 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Province_Code string `json:"province_code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -22,10 +22,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Installation_Id *uint16 `json:"installation_id"`
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Installation_Id *uint16 `json:"installation_id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -19,9 +19,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -22,8 +22,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Id uint `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -17,10 +17,8 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint32 `json:"id"`
|
||||
District_Code string `json:"district_code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Id uint32 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -24,7 +24,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
pl.SetLogInfo(&event, input.Sanitize(), "started", "create")
|
||||
|
||||
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
@@ -34,6 +34,15 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if input.Person_Id == nil {
|
||||
if err := createPerson(&input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := createUser(&input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
@@ -87,6 +96,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(input.Includes) > 0 {
|
||||
input.Preloads = pu.GetPreloads(input.Includes)
|
||||
}
|
||||
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,14 @@ Any functions that are used internally by the use-case
|
||||
package employee
|
||||
|
||||
import (
|
||||
"errors"
|
||||
e "simrs-vx/internal/domain/main-entities/employee"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
|
||||
up "simrs-vx/internal/use-case/main-use-case/person"
|
||||
uu "simrs-vx/internal/use-case/main-use-case/user"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Employee) {
|
||||
@@ -24,3 +31,40 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Employee) {
|
||||
data.Number = inputSrc.Number
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
}
|
||||
|
||||
func createUser(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
|
||||
if input.UserRequest == nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-create-fail",
|
||||
Detail: "user request is required",
|
||||
Raw: errors.New("user request is required"),
|
||||
}
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
user, err := uu.CreateData(*input.UserRequest, event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input.User_Id = &user.Id
|
||||
return nil
|
||||
}
|
||||
|
||||
func createPerson(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
|
||||
if input.PersonRequest == nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-create-fail",
|
||||
Detail: "person request is required",
|
||||
Raw: errors.New("person request is required"),
|
||||
}
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
person, err := up.CreateData(*input.PersonRequest, event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input.Person_Id = &person.Id
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
@@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Em
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if len(input.Preloads) > 0 {
|
||||
for _, preload := range input.Preloads {
|
||||
tx = tx.Preload(preload)
|
||||
}
|
||||
}
|
||||
|
||||
tx = tx.
|
||||
Model(&e.Employee{}).
|
||||
Scopes(gh.Filter(input)).
|
||||
Scopes(gh.Filter(input.FilterDto)).
|
||||
Count(&count).
|
||||
Scopes(gh.Paginate(input, &pagination)).
|
||||
Order("\"CreatedAt\" DESC")
|
||||
|
||||
@@ -80,3 +80,24 @@ func HandleMiddlewareError(event *pl.Event, mwType, mwName string, logData inter
|
||||
func AddPrefix(prefix string, str string) string {
|
||||
return prefix + str
|
||||
}
|
||||
|
||||
func GetPreloads(input string) []string {
|
||||
result := []string{}
|
||||
parts := strings.Split(input, ",")
|
||||
for _, p := range parts {
|
||||
result = append(result, kebabToPascal(p))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func kebabToPascal(input string) string {
|
||||
parts := strings.Split(input, "-")
|
||||
for i, p := range parts {
|
||||
if len(p) > 0 {
|
||||
r := []rune(p)
|
||||
r[0] = []rune(strings.ToUpper(string(r[0])))[0]
|
||||
parts[i] = string(r)
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user