comnpany to cm

This commit is contained in:
ctengiz
2024-06-14 17:19:38 +03:00
parent a28576960e
commit f54c5660ea
15 changed files with 50 additions and 74 deletions

View File

@@ -13,7 +13,7 @@ create table company (
constraint uq_company unique (clid, code) constraint uq_company unique (clid, code)
); );
CREATE TRIGGER zl_company before INSERT or UPDATE ON company CREATE TRIGGER zl_company before INSERT or UPDATE ON cm
FOR EACH ROW EXECUTE FUNCTION zllog(); FOR EACH ROW EXECUTE FUNCTION zllog();
create table company_usr ( create table company_usr (
@@ -22,5 +22,5 @@ create table company_usr (
usr_id dmn_usrid, usr_id dmn_usrid,
constraint uq_company_usr unique (company_id, usr_id), constraint uq_company_usr unique (company_id, usr_id),
constraint fk_company_usr_company foreign key (company_id) constraint fk_company_usr_company foreign key (company_id)
references company(id) on update cascade on delete cascade references cm(id) on update cascade on delete cascade
); );

View File

@@ -1 +1 @@
alter table company add tmpl jsonb; alter table cm add tmpl jsonb;

View File

@@ -0,0 +1,12 @@
alter table public.cm
rename to cm;
alter table public.cm
rename column title to name;
alter table public.company_usr
rename to cm_usr;
alter table public.cm_usr
rename column company_id to cm_id;

View File

@@ -1,13 +1,13 @@
-- << Create -- << Create
insert into company ( clid insert into cm ( clid
, code , code
, title , name
, is_active , is_active
, notes , notes
, tmpl) , tmpl)
values ( @clid values ( @clid
, @code , @code
, @title , @name
, @is_active , @is_active
, @notes , @notes
, @tmpl) , @tmpl)
@@ -18,20 +18,19 @@ returning id
select clid select clid
, id , id
, code , code
, title , name
, is_active , is_active
, notes , notes
, tmpl , tmpl
from company from cm
where id = $1 where id = $1
-- Read >> -- Read >>
-- << Update -- << Update
update company update cm
set clid = @clid set code = @code
, code = @code , name = @name
, title = @title
, is_active = @is_active , is_active = @is_active
, notes = @notes , notes = @notes
, tmpl = @tmpl , tmpl = @tmpl
@@ -41,7 +40,7 @@ where id = @id
-- << Delete -- << Delete
delete delete
from company from cm
where id = $1 where id = $1
-- Delete >> -- Delete >>
@@ -49,12 +48,12 @@ where id = $1
select clid select clid
, id , id
, code , code
, title , name
, is_active , is_active
, notes , notes
, tmpl , tmpl
from company {{.Where}} from cm {{.Where}}
{{.OrderBy}} {{.OrderBy}}
{{.Rows}} {{.Rows}}
-- List >> -- List >>

View File

@@ -5,7 +5,7 @@ import (
"git.makki.io/makki/libgo/cmn" "git.makki.io/makki/libgo/cmn"
"git.makki.io/makki/libgo/dbu" "git.makki.io/makki/libgo/dbu"
"git.makki.io/makki/libgo/mhttp" "git.makki.io/makki/libgo/mhttp"
"git.makki.io/makki/libgo/nauth" "git.notitek.com.tr/common/notgo/nauth"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"net/http" "net/http"
) )
@@ -146,7 +146,7 @@ func companyList(w http.ResponseWriter, r *http.Request) {
return return
} }
rp, err := dbu.NewRepoWithFile(r.Context(), "company", nil) rp, err := dbu.NewRepoWithFile(r.Context(), "cm", nil)
if err != nil { if err != nil {
mhttp.InternalServerError(w, err) mhttp.InternalServerError(w, err)
return return

View File

@@ -19,7 +19,7 @@ func tmplPost(w http.ResponseWriter, r *http.Request) {
return return
} }
sq := "update company set tmpl = $2 where id = $1" sq := "update cm set tmpl = $2 where id = $1"
_, err = dbu.DB.Exec(r.Context(), sq, companyID, body) _, err = dbu.DB.Exec(r.Context(), sq, companyID, body)
if err != nil { if err != nil {
mhttp.InternalServerError(w, err) mhttp.InternalServerError(w, err)
@@ -33,7 +33,7 @@ func tmplGet(w http.ResponseWriter, r *http.Request) {
companyID := cmn.StrToInt64(chi.URLParam(r, "companyID")) companyID := cmn.StrToInt64(chi.URLParam(r, "companyID"))
var body json.RawMessage var body json.RawMessage
sq := "select tmpl from company where id = $1" sq := "select tmpl from cm where id = $1"
err := dbu.DB.QueryRow(r.Context(), sq, companyID).Scan(&body) err := dbu.DB.QueryRow(r.Context(), sq, companyID).Scan(&body)
if err != nil { if err != nil {
mhttp.InternalServerError(w, err) mhttp.InternalServerError(w, err)

View File

@@ -1,18 +0,0 @@
package public
import (
"git.makki.io/makki/libgo/mhttp"
"git.makki.io/makki/libgo/svc"
"net/http"
)
func login(w http.ResponseWriter, r *http.Request) {
authResp, err := svc.S.Authenticate(r)
if err != nil {
mhttp.InternalServerError(w, err)
return
}
clientResp := authResp.GetEndUserResponse()
mhttp.ResponseSuccess(w, clientResp)
}

View File

@@ -1,14 +0,0 @@
package public
import (
"github.com/go-chi/chi/v5"
"net/http"
)
func Router() http.Handler {
r := chi.NewRouter()
// user authentication
r.Post("/login", login)
return r
}

View File

@@ -1,10 +1,9 @@
package api package api
import ( import (
"bordro-esleme/api/public"
"fmt" "fmt"
"git.makki.io/makki/libgo/napi" "git.notitek.com.tr/common/notgo/napi"
"git.makki.io/makki/libgo/nauth" "git.notitek.com.tr/common/notgo/nauth"
"net/http" "net/http"
"os" "os"
"path" "path"
@@ -51,8 +50,7 @@ func HttpHandler(re enums.TRunEnv) http.Handler {
mux.Route("/api", func(mr chi.Router) { mux.Route("/api", func(mr chi.Router) {
// Public Route endpoints // Public Route endpoints
mr.Mount("/", public.Router()) mr.Post("/login", napi.Login)
//mr.Mount("/admin", admin.Router())
//protected end points //protected end points
mr.Group(func(r chi.Router) { mr.Group(func(r chi.Router) {

View File

@@ -5,6 +5,7 @@ import (
"git.makki.io/makki/libgo/dbu" "git.makki.io/makki/libgo/dbu"
"git.makki.io/makki/libgo/mlog" "git.makki.io/makki/libgo/mlog"
"git.makki.io/makki/libgo/svc" "git.makki.io/makki/libgo/svc"
"git.notitek.com.tr/common/notgo/nauth"
"time" "time"
) )
@@ -35,7 +36,7 @@ func main() {
if svc.S.DevMode() { if svc.S.DevMode() {
expire = time.Hour * 48 expire = time.Hour * 48
} }
err = s.SubscribeToAuthServer(expire) err = nauth.SubscribeToAuthServer(s.Ctx, expire)
if err != nil { if err != nil {
mlog.Fatal(err) mlog.Fatal(err)
} }

View File

@@ -9,10 +9,10 @@ import (
) )
type Company struct { type Company struct {
Clid int64 `db:"clid" json:"-"` ClID int64 `db:"clid" json:"-"`
ID int64 `db:"id"` ID int64 `db:"id"`
Code string `db:"code"` Code string `db:"code"`
Title null.String `db:"title"` Name null.String `db:"name"`
IsActive bool `db:"is_active"` IsActive bool `db:"is_active"`
Notes null.String `db:"notes"` Notes null.String `db:"notes"`
@@ -30,7 +30,7 @@ func New() *Company {
} }
func DbRead(ctx context.Context, id int64) (*Company, error) { func DbRead(ctx context.Context, id int64) (*Company, error) {
rp, err := dbu.NewRepoWithFile(ctx, "company", nil) rp, err := dbu.NewRepoWithFile(ctx, "cm", nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -55,7 +55,7 @@ func DbDelete(ctx context.Context, id int64, log bool, usrID *int64) error {
} }
defer tx.Rollback(ctx) defer tx.Rollback(ctx)
rp, err := dbu.NewRepoWithFile(ctx, "company", tx) rp, err := dbu.NewRepoWithFile(ctx, "cm", tx)
if err != nil { if err != nil {
return err return err
} }
@@ -66,7 +66,7 @@ func DbDelete(ctx context.Context, id int64, log bool, usrID *int64) error {
if err != nil { if err != nil {
return dbu.ParsedErrSuppressNoRows(err) return dbu.ParsedErrSuppressNoRows(err)
} }
err = dbu.DB.LogDMLTx("d", "company", oldData.ID, usrID, "", oldData, nil, tx) err = dbu.DB.LogDMLTx("d", "cm", oldData.ID, usrID, "", oldData, nil, tx)
if err != nil { if err != nil {
slog.Error(err.Error()) slog.Error(err.Error())
} }
@@ -81,9 +81,9 @@ func DbDelete(ctx context.Context, id int64, log bool, usrID *int64) error {
} }
func (m *Company) DbCreate(ctx context.Context, clID int64, log bool, usrID *int64) error { func (m *Company) DbCreate(ctx context.Context, clID int64, log bool, usrID *int64) error {
m.Clid = clID m.ClID = clID
rp, err := dbu.NewRepoWithFile(ctx, "company", nil) rp, err := dbu.NewRepoWithFile(ctx, "cm", nil)
if err != nil { if err != nil {
return err return err
} }
@@ -94,7 +94,7 @@ func (m *Company) DbCreate(ctx context.Context, clID int64, log bool, usrID *int
} }
if log { if log {
err = dbu.DB.LogDMLTx("c", "company", m.ID, usrID, "", nil, m, nil) err = dbu.DB.LogDMLTx("c", "cm", m.ID, usrID, "", nil, m, nil)
if err != nil { if err != nil {
slog.Error(err.Error()) slog.Error(err.Error())
} }
@@ -110,7 +110,7 @@ func (m *Company) DbUpdate(ctx context.Context, log bool, usrID *int64) error {
} }
defer tx.Rollback(ctx) defer tx.Rollback(ctx)
rp, err := dbu.NewRepoWithFile(ctx, "company", tx) rp, err := dbu.NewRepoWithFile(ctx, "cm", tx)
if err != nil { if err != nil {
return err return err
} }
@@ -121,7 +121,7 @@ func (m *Company) DbUpdate(ctx context.Context, log bool, usrID *int64) error {
if err != nil { if err != nil {
return err return err
} }
err = dbu.DB.LogDMLTx("u", "company", oldData.ID, usrID, "", oldData, m, tx) err = dbu.DB.LogDMLTx("u", "cm", oldData.ID, usrID, "", oldData, m, tx)
if err != nil { if err != nil {
slog.Error(err.Error()) slog.Error(err.Error())
} }

View File

@@ -5,14 +5,12 @@ const t = i18n.global.t
class Company extends Model { class Company extends Model {
ID = null ID = null
Code = '' Code = ''
Title = '' Name = ''
IsActive = true IsActive = true
Notes = '' Notes = ''
Tmpl = '' Tmpl = ''
_colOptions = { _colOptions = {
ID: { ID: {
label: t('Company.ID'), label: t('Company.ID'),
@@ -40,7 +38,7 @@ class Company extends Model {
}, },
Title: { Name: {
label: t('Company.Title'), label: t('Company.Title'),
visible: true, visible: true,
dataType: 'text', //numeric, text, date, bool, datetime, time, inet dataType: 'text', //numeric, text, date, bool, datetime, time, inet

View File

@@ -21,7 +21,7 @@
/> />
<q-input class="col-xs-12 col-sm-6" <q-input class="col-xs-12 col-sm-6"
v-model="model.Title" v-model="model.Name"
:label="t('Company.Title')" :label="t('Company.Title')"
bottom-slots bottom-slots
:rules="[]" :rules="[]"

View File

@@ -10,7 +10,7 @@
:label="t('selectCompany')" :label="t('selectCompany')"
:options="ld.companies" :options="ld.companies"
option-value="ID" option-value="ID"
option-label="Title" option-label="Name"
dense dense
options-dense options-dense
outlined outlined

View File

@@ -15,7 +15,7 @@
:label="t('selectCompany')" :label="t('selectCompany')"
:options="ld.companies" :options="ld.companies"
option-value="ID" option-value="ID"
option-label="Title" option-label="Name"
dense dense
options-dense options-dense
outlined outlined