update model
This commit is contained in:
@@ -151,7 +151,7 @@ func (lh *MasterKelainanHandler) HandlerShowMasterKelainan(c echo.Context) error
|
||||
Link: "/dev/kelainan/add",
|
||||
HxTarget: "#" + dialogAddBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #" + searchID + ", #currpage" + paginationID,
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #" + searchID + ", #currpage" + paginationID + ",#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID",
|
||||
ModalID: dialogAddID,
|
||||
ModalTitle: "New - Grup Kelainan",
|
||||
DialogBody: dialogAddBodyCmp,
|
||||
@@ -222,7 +222,7 @@ func (lh *MasterKelainanHandler) HandlerShowMasterKelainan(c echo.Context) error
|
||||
Link: "/dev/kelainan/edit",
|
||||
HxTarget: "#" + dialogEditBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID + ",#dialogDeleteBodyID, #dialogDeleteID",
|
||||
ModalID: dialogEditID,
|
||||
ModalTitle: "New - Grup Kelainan",
|
||||
DialogBody: dialogEditBodyComponent,
|
||||
@@ -260,7 +260,7 @@ func (lh *MasterKelainanHandler) HandlerShowMasterKelainan(c echo.Context) error
|
||||
Link: "/dev/kelainan/delete",
|
||||
HxTarget: "#" + dialogDeleteBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #" + searchID + ", #currpage" + paginationID,
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #" + searchID + ", #currpage" + paginationID + ",#dialogEditBodyID, #dialogEditID",
|
||||
ModalID: dialogDeleteID,
|
||||
ModalTitle: "Konfirmasi",
|
||||
DialogBody: dialogDeleteBodyComponent,
|
||||
|
||||
@@ -6,6 +6,7 @@ type Kelainan struct {
|
||||
Nomor string `db:"nomor"`
|
||||
Mcu_KelainanGroupID int `db:"Mcu_KelainanGroupID"`
|
||||
Mcu_KelainanGroupName string `db:"Mcu_KelainanGroupName"`
|
||||
Mcu_KelainanGroupFlagActive string `db:"Mcu_KelainanGroupFlagActive"`
|
||||
Mcu_KelainanGroupIsActive string `db:"Mcu_KelainanGroupIsActive"`
|
||||
Mcu_KelainanGroupCreated string `db:"Mcu_KelainanGroupCreated"`
|
||||
Mcu_KelainanGroupCreatedUserID string `db:"Mcu_KelainanGroupCreatedUserID"`
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
dbx "cpone/package/database"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -99,6 +100,7 @@ func (su *ServicesMasterKelainan) GetListMasterKelainan(search string, currentPa
|
||||
ROW_NUMBER() OVER (ORDER BY Mcu_KelainanGroupID DESC) AS nomor,
|
||||
Mcu_KelainanGroupID,
|
||||
Mcu_KelainanGroupName,
|
||||
Mcu_KelainanGroupFlagActive,
|
||||
Mcu_KelainanGroupIsActive,
|
||||
Mcu_KelainanGroupCreated,
|
||||
Mcu_KelainanGroupLastUpdated
|
||||
@@ -138,12 +140,33 @@ func (su *ServicesMasterKelainan) AddKelainan(name string) (models.Kelainan, err
|
||||
logger, _ := zap.NewProduction()
|
||||
var data models.Kelainan
|
||||
|
||||
var datacek []models.Kelainan
|
||||
|
||||
qryCek := `SELECT Mcu_KelainanGroupName FROM mcu_kelainangroup
|
||||
WHERE Mcu_KelainanGroupName = ? AND Mcu_KelainanGroupIsActive = 'Y'`
|
||||
err := dbx.Handlex.Select(&datacek, qryCek, name)
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error cek data by name",
|
||||
zap.Any("datacek", datacek),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED")
|
||||
}
|
||||
if len(datacek) > 0 {
|
||||
defer logger.Sync()
|
||||
logger.Error("Name already taken by another data",
|
||||
zap.String("name", name),
|
||||
)
|
||||
return data, fmt.Errorf("name sudah dipakai")
|
||||
}
|
||||
|
||||
qry := `INSERT INTO mcu_kelainangroup(
|
||||
Mcu_KelainanGroupName,
|
||||
Mcu_KelainanGroupCreated,
|
||||
Mcu_KelainanGroupLastUpdated) VALUES(?,NOW(),NOW())`
|
||||
rst := dbx.Handlex.MustExec(qry, name)
|
||||
_, err := rst.LastInsertId()
|
||||
insertedID, err := rst.LastInsertId()
|
||||
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
@@ -153,6 +176,16 @@ func (su *ServicesMasterKelainan) AddKelainan(name string) (models.Kelainan, err
|
||||
return data, fmt.Errorf("QUERY_FAILED")
|
||||
}
|
||||
|
||||
s := strconv.Itoa(int(insertedID))
|
||||
data, err = su.GetKelainanByID(s)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Error("Error get kelainan by id",
|
||||
zap.String("name", name),
|
||||
)
|
||||
return data, fmt.Errorf("QUERY_FAILED")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user