diff --git a/README.md b/README.md index 8eb7336..3503106 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ Backend mapping: | `createUnderParent` | `({ googleAuthId, parentId, name })` | `{ id, parentId, sort, name }` | | `delete` | `({ googleAuthId, id })` | `void` — blocked by FK if `categoryarticle` or child categories remain | | `getTreeForCompany` | `(googleAuthId, companyId)` | `{ languageId, tree, articles }` | +| `getCategoryArticles` | `(googleAuthId, categoryId)` | `{ id, sku, name, slug, net, taxRate, optionsCount, articleListCount, childCount, thumbW, thumbH, thumbHash }[]` | ### `createUnderParent` (transaction) diff --git a/generate-schema-graph.js b/generate-schema-graph.js index e3813c3..7cd76be 100644 --- a/generate-schema-graph.js +++ b/generate-schema-graph.js @@ -269,6 +269,7 @@ const CLUSTERS = [ 'meta', 'google_auth', 'companyuser', + 'syncpos', 'company', 'customergroup', 'entity', diff --git a/schema-graph.dot b/schema-graph.dot index f5f050a..bc60456 100644 --- a/schema-graph.dot +++ b/schema-graph.dot @@ -9,11 +9,12 @@ digraph schema { label="Identity & Company"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#ffffff60"; color="#a0aec0"; fontcolor="#1a365d"; margin=14; + numbers [label=<
numbers
idINT PK
company_idINT FK
typeNVARCHAR(100)
prefixNVARCHAR(50)
paddingINT
nextINT
>]; meta [label=<
meta
keyNVARCHAR(255)
valueNVARCHAR(MAX)
>]; entity [label=<
entity
idINT PK
customergroup_idINT FK
firstnameNVARCHAR(255)
lastnameNVARCHAR(255)
>]; - numbers [label=<
numbers
idINT PK
company_idINT FK
typeNVARCHAR(100)
prefixNVARCHAR(50)
paddingINT
nextINT
>]; + syncpos [label=<
syncpos
idINT PK
company_idINT FK
paircodeNVARCHAR(50)
token?NVARCHAR(255)
>]; companyuser [label=<
companyuser
idINT PK
company_idINT FK
google_auth_idINT FK
>]; - company [label=<
company
idINT PK
poscustomergroup_id?INT FK
taxrate?INT FK
reducedtaxrate?INT FK
taxfreerate?INT FK
default_language_id?INT FK
root_category_id?INT FK
nameNVARCHAR(255)
>]; + company [label=<
company
idINT PK
poscustomergroup_id?INT FK
taxrate?INT FK
reducedtaxrate?INT FK
taxfreerate?INT FK
default_language_id?INT FK
root_category_id?INT FK
nameNVARCHAR(255)
>]; google_auth [label=<
google_auth
idINT PK
selected_company?INT FK
emailNVARCHAR(320)
created_atDATETIME2
>]; customergroup [label=<
customergroup
idINT PK
company_idINT FK
nameNVARCHAR(255)
>]; } @@ -30,14 +31,14 @@ digraph schema { label="Catalog"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#ffffff60"; color="#a0aec0"; fontcolor="#1a365d"; margin=14; - category [label=<
category
idINT PK
parent_id?INT FK
sortINT
>]; - categoryarticle [label=<
categoryarticle
idINT PK
category_idINT FK
article_idINT FK
>]; articlehistory [label=<
articlehistory
idINT PK
article_idINT FK
dateDATETIME2
textNVARCHAR(MAX)
>]; - article [label=<
article
idINT PK
unit_idINT FK
fatherarticle_id?INT FK
articlelist_id?INT FK
optionslist_id?INT FK
brand_id?INT FK
sku?NVARCHAR(100)
unitamountFLOAT
weightFLOAT
is_fatherBIT
fathersortINT
created_atDATETIME2
updated_atDATETIME2
>]; + category [label=<
category
idINT PK
parent_id?INT FK
sortINT
>]; articleean [label=<
articleean
idINT PK
article_idINT FK
eanNVARCHAR(50)
>]; + article [label=<
article
idINT PK
unit_idINT FK
fatherarticle_id?INT FK
articlelist_id?INT FK
optionslist_id?INT FK
brand_id?INT FK
sku?NVARCHAR(100)
unitamountFLOAT
weightFLOAT
is_fatherBIT
fathersortINT
created_atDATETIME2
updated_atDATETIME2
>]; + categoryarticle [label=<
categoryarticle
idINT PK
category_idINT FK
article_idINT FK
>]; articlelist [label=<
articlelist
idINT PK
>]; - articlelistarticle [label=<
articlelistarticle
idINT PK
article_idINT FK
articlelist_idINT FK
countINT
sortINT
>]; optionslist [label=<
optionslist
idINT PK
>]; + articlelistarticle [label=<
articlelistarticle
idINT PK
article_idINT FK
articlelist_idINT FK
countINT
sortINT
>]; brand [label=<
brand
idINT PK
nameNVARCHAR(255)
gsprpinfo?NVARCHAR(MAX)
>]; optionslistarticle [label=<
optionslistarticle
idINT PK
article_idINT FK
optionslist_idINT FK
countINT
sortINT
mandatedBIT
>]; } @@ -68,14 +69,14 @@ digraph schema { __legend [label=<
Legend
PKprimary key
FKforeign key
?nullable column
—FOREIGN KEY constraint
- -naming convention only, no constraint
>]; - google_auth:selected_company:sw -> company:in2:n [color="#c53030", fontcolor="#c53030", tooltip="FK_google_auth_selected_company"]; + google_auth:selected_company:sw -> company:in3:n [color="#c53030", fontcolor="#c53030", tooltip="FK_google_auth_selected_company"]; category:parent_id:e -> category:id:e [color="#2f855a", fontcolor="#2f855a", tooltip="FK_category_parent"]; company:root_category_id:e -> category:in0:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_company_root_category"]; company:default_language_id:e -> language:in0:n [color="#b7791f", fontcolor="#b7791f", tooltip="FK_company_default_language"]; company:taxrate:se -> tax:in2:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_company_taxrate"]; company:reducedtaxrate:se -> tax:in0:n [color="#c05621", fontcolor="#c05621", tooltip="FK_company_reducedtaxrate"]; company:taxfreerate:se -> tax:in1:n [color="#319795", fontcolor="#319795", tooltip="FK_company_taxfreerate"]; - customergroup:company_id:nw -> company:in3:n [color="#97266d", fontcolor="#97266d", tooltip="FK_customergroup_company"]; + customergroup:company_id:nw -> company:in4:n [color="#97266d", fontcolor="#97266d", tooltip="FK_customergroup_company"]; company:poscustomergroup_id:se -> customergroup:in1:n [color="#4c51bf", fontcolor="#4c51bf", tooltip="FK_company_poscustomergroup"]; entity:customergroup_id:se -> customergroup:in0:n [color="#276749", fontcolor="#276749", tooltip="FK_entity_customergroup"]; unittext:unit_id:se -> unit:in0:n [color="#9c4221", fontcolor="#9c4221", tooltip="FK_unittext_unit"]; @@ -85,8 +86,8 @@ digraph schema { article:articlelist_id:se -> articlelist:in0:n [color="#22543d", fontcolor="#22543d", tooltip="FK_article_articlelist"]; article:optionslist_id:se -> optionslist:in0:n [color="#1a365d", fontcolor="#1a365d", tooltip="FK_article_optionslist"]; article:fatherarticle_id:e -> article:id:e [color="#702459", fontcolor="#702459", tooltip="FK_article_fatherarticle"]; - articlehistory:article_id:se -> article:in4:n [color="#744210", fontcolor="#744210", tooltip="FK_articlehistory_article"]; - articleean:article_id:sw -> article:in6:n [color="#285e61", fontcolor="#285e61", tooltip="FK_articleean_article"]; + articlehistory:article_id:se -> article:in3:n [color="#744210", fontcolor="#744210", tooltip="FK_articlehistory_article"]; + articleean:article_id:se -> article:in4:n [color="#285e61", fontcolor="#285e61", tooltip="FK_articleean_article"]; articlepic:article_id:w -> article:in9:n [color="#d53f8c", fontcolor="#d53f8c", tooltip="FK_articlepic_article"]; articlepic:pic_id:sw -> pic:in1:n [color="#dd6b20", fontcolor="#dd6b20", tooltip="FK_articlepic_pic"]; brandpic:brand_id:sw -> brand:in1:n [color="#38a169", fontcolor="#38a169", tooltip="FK_brandpic_brand"]; @@ -94,9 +95,9 @@ digraph schema { articlelistarticle:articlelist_id:sw -> articlelist:in1:n [color="#805ad5", fontcolor="#805ad5", tooltip="FK_articlelistarticle_articlelist"]; articlelistarticle:article_id:sw -> article:in7:n [color="#c53030", fontcolor="#c53030", tooltip="FK_articlelistarticle_article"]; optionslistarticle:optionslist_id:sw -> optionslist:in1:n [color="#2f855a", fontcolor="#2f855a", tooltip="FK_optionslistarticle_optionslist"]; - optionslistarticle:article_id:sw -> article:in8:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_optionslistarticle_article"]; + optionslistarticle:article_id:w -> article:in8:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_optionslistarticle_article"]; categoryarticle:category_id:sw -> category:in3:n [color="#b7791f", fontcolor="#b7791f", tooltip="FK_categoryarticle_category"]; - categoryarticle:article_id:se -> article:in3:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_categoryarticle_article"]; + categoryarticle:article_id:sw -> article:in6:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_categoryarticle_article"]; categorypic:category_id:w -> category:in4:n [color="#c05621", fontcolor="#c05621", tooltip="FK_categorypic_category"]; categorypic:pic_id:se -> pic:in0:n [color="#319795", fontcolor="#319795", tooltip="FK_categorypic_pic"]; categorytext:category_id:se -> category:in1:n [color="#97266d", fontcolor="#97266d", tooltip="FK_categorytext_category"]; @@ -109,7 +110,8 @@ digraph schema { manifestarticle:manifest_id:sw -> manifest:in0:n [color="#22543d", fontcolor="#22543d", tooltip="FK_manifestarticle_manifest"]; manifestarticle:article_id:e -> article:in1:n [color="#1a365d", fontcolor="#1a365d", tooltip="FK_manifestarticle_article"]; manifestarticle:tax_id:sw -> tax:in4:n [color="#702459", fontcolor="#702459", tooltip="FK_manifestarticle_tax"]; - numbers:company_id:se -> company:in0:n [color="#744210", fontcolor="#744210", tooltip="FK_numbers_company"]; + numbers:company_id:e -> company:in0:n [color="#744210", fontcolor="#744210", tooltip="FK_numbers_company"]; companyuser:google_auth_id:se -> google_auth:in0:n [color="#285e61", fontcolor="#285e61", tooltip="FK_companyuser_google_auth"]; - companyuser:company_id:se -> company:in1:n [color="#d53f8c", fontcolor="#d53f8c", tooltip="FK_companyuser_company"]; + companyuser:company_id:se -> company:in2:n [color="#d53f8c", fontcolor="#d53f8c", tooltip="FK_companyuser_company"]; + syncpos:company_id:se -> company:in1:n [color="#dd6b20", fontcolor="#dd6b20", tooltip="FK_syncpos_company"]; } \ No newline at end of file diff --git a/schema-graph.svg b/schema-graph.svg index b43fd1a..15c1333 100644 --- a/schema-graph.svg +++ b/schema-graph.svg @@ -4,276 +4,311 @@ - + schema - + cluster_identity - + Identity & Company cluster_i18n - -Localization + +Localization cluster_catalog - -Catalog + +Catalog cluster_media - -Media + +Media cluster_commerce - -Pricing & Documents + +Pricing & Documents cluster_units - -Units + +Units + + + +numbers + + +numbers + + +id +INT +PK + + +company_id +INT +FK + + +type +NVARCHAR(100) + + +prefix +NVARCHAR(50) + + +padding +INT + + +next +INT + + + +company + + + + + + + +company + + +id +INT +PK + + +poscustomergroup_id +? +INT +FK + + +taxrate +? +INT +FK + + +reducedtaxrate +? +INT +FK + + +taxfreerate +? +INT +FK + + +default_language_id +? +INT +FK + + +root_category_id +? +INT +FK + + +name +NVARCHAR(255) + + + +numbers:e->company:n + + + + + - + meta - - -meta - - -key -NVARCHAR(255) - - -value -NVARCHAR(MAX) + + +meta + + +key +NVARCHAR(255) + + +value +NVARCHAR(MAX) - + entity - - -entity - - -id -INT -PK - - -customergroup_id -INT -FK - - -firstname -NVARCHAR(255) - - -lastname -NVARCHAR(255) + + +entity + + +id +INT +PK + + +customergroup_id +INT +FK + + +firstname +NVARCHAR(255) + + +lastname +NVARCHAR(255) - + customergroup - - - - - -customergroup - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) + + + + + +customergroup + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) entity:se->customergroup:n - - + + - - -numbers - - -numbers - - -id -INT -PK - - -company_id -INT -FK - - -type -NVARCHAR(100) - - -prefix -NVARCHAR(50) - - -padding -INT - - -next -INT + + +syncpos + + +syncpos + + +id +INT +PK + + +company_id +INT +FK + + +paircode +NVARCHAR(50) + + +token? +NVARCHAR(255) - - -company - - - - - - -company - - -id -INT -PK - - -poscustomergroup_id -? -INT -FK - - -taxrate -? -INT -FK - - -reducedtaxrate -? -INT -FK - - -taxfreerate -? -INT -FK - - -default_language_id -? -INT -FK - - -root_category_id -? -INT -FK - - -name -NVARCHAR(255) - - - -numbers:se->company:n - - - + + +syncpos:se->company:n + + + - + companyuser - - -companyuser - - -id -INT -PK - - -company_id -INT -FK - - -google_auth_id -INT -FK + + +companyuser + + +id +INT +PK + + +company_id +INT +FK + + +google_auth_id +INT +FK companyuser:se->company:n - - + + - + google_auth - - - -google_auth - - -id -INT -PK - - -selected_company -? -INT -FK - - -email -NVARCHAR(320) - - -created_at -DATETIME2 + + + +google_auth + + +id +INT +PK + + +selected_company +? +INT +FK + + +email +NVARCHAR(320) + + +created_at +DATETIME2 companyuser:se->google_auth:n - - + + @@ -281,103 +316,103 @@ company:se->customergroup:n - - + + - + language - - - - - - -language - - -id -INT -PK - - -iso639 -NVARCHAR(10) + + + + + + +language + + +id +INT +PK + + +iso639 +NVARCHAR(10) company:e->language:n - - + + - + category - - - - - - - -category - - -id -INT -PK - - -parent_id -? -INT -FK - - -sort -INT + + + + + + + +category + + +id +INT +PK + + +parent_id +? +INT +FK + + +sort +INT company:e->category:n - - + + - + tax - - - - - - - -tax - - -id -INT -PK - - -rate -DECIMAL(18,4) + + + + + + + +tax + + +id +INT +PK + + +rate +DECIMAL(18,4) company:se->tax:n - - + + @@ -385,8 +420,8 @@ company:se->tax:n - - + + @@ -394,8 +429,8 @@ company:se->tax:n - - + + @@ -403,8 +438,8 @@ google_auth:sw->company:n - - + + @@ -412,129 +447,129 @@ customergroup:nw->company:n - - + + - + unittext - - -unittext - - -id -INT -PK - - -language_id -INT -FK - - -unit_id -INT -FK - - -symbol -NVARCHAR(50) - - -name -NVARCHAR(255) + + +unittext + + +id +INT +PK + + +language_id +INT +FK + + +unit_id +INT +FK + + +symbol +NVARCHAR(50) + + +name +NVARCHAR(255) unittext:se->language:n - - + + - + unit - - - - -unit - - -id -INT -PK - - -si -NVARCHAR(50) - - -basesi -NVARCHAR(50) - - -basesifactor -FLOAT + + + + +unit + + +id +INT +PK + + +si +NVARCHAR(50) + + +basesi +NVARCHAR(50) + + +basesifactor +FLOAT unittext:se->unit:n - - + + - + categorytext - - -categorytext - - -id -INT -PK - - -language_id -INT -FK - - -category_id -INT -FK - - -name -NVARCHAR(255) - - -slug -NVARCHAR(255) - - -seo? -NVARCHAR(MAX) - - -desc? -NVARCHAR(MAX) + + +categorytext + + +id +INT +PK + + +language_id +INT +FK + + +category_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) categorytext:sw->language:n - - + + @@ -542,143 +577,177 @@ categorytext:se->category:n - - + + - + articletext - - -articletext - - -id -INT -PK - - -language_id -INT -FK - - -article_id -INT -FK - - -name -NVARCHAR(255) - - -slug -NVARCHAR(255) - - -seo? -NVARCHAR(MAX) - - -desc? -NVARCHAR(MAX) + + +articletext + + +id +INT +PK + + +language_id +INT +FK + + +article_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) articletext:sw->language:n - - + + - + article - - - - - - - - - - - - -article - - -id -INT -PK - - -unit_id -INT -FK - - -fatherarticle_id -? -INT -FK - - -articlelist_id -? -INT -FK - - -optionslist_id -? -INT -FK - - -brand_id -? -INT -FK - - -sku? -NVARCHAR(100) - - -unitamount -FLOAT - - -weight -FLOAT - - -is_father -BIT - - -fathersort -INT - - -created_at -DATETIME2 - - -updated_at -DATETIME2 + + + + + + + + + + + + +article + + +id +INT +PK + + +unit_id +INT +FK + + +fatherarticle_id +? +INT +FK + + +articlelist_id +? +INT +FK + + +optionslist_id +? +INT +FK + + +brand_id +? +INT +FK + + +sku? +NVARCHAR(100) + + +unitamount +FLOAT + + +weight +FLOAT + + +is_father +BIT + + +fathersort +INT + + +created_at +DATETIME2 + + +updated_at +DATETIME2 articletext:e->article:n - - + + + + + + + +articlehistory + + +articlehistory + + +id +INT +PK + + +article_id +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) + + + +articlehistory:se->article:n + + + @@ -686,82 +755,38 @@ category:e->category:e - - + + - - -categoryarticle - - -categoryarticle - - -id -INT -PK - - -category_id -INT -FK - - -article_id -INT -FK + + +articleean + + +articleean + + +id +INT +PK + + +article_id +INT +FK + + +ean +NVARCHAR(50) - - -categoryarticle:sw->category:n - - - - - - - - -categoryarticle:se->article:n - - - - - - - - -articlehistory - - -articlehistory - - -id -INT -PK - - -article_id -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) - - - -articlehistory:se->article:n - - - + + +articleean:se->article:n + + + @@ -769,85 +794,85 @@ article:e->article:e - - + + - + articlelist - - - - -articlelist - - -id -INT -PK + + + + +articlelist + + +id +INT +PK article:se->articlelist:n - - + + optionslist - - - - -optionslist - - -id -INT -PK + + + + +optionslist + + +id +INT +PK article:se->optionslist:n - - + + - + brand - - - - -brand - - -id -INT -PK - - -name -NVARCHAR(255) - - -gsprpinfo? -NVARCHAR(MAX) + + + + +brand + + +id +INT +PK + + +name +NVARCHAR(255) + + +gsprpinfo? +NVARCHAR(MAX) article:e->brand:n - - + + @@ -855,77 +880,87 @@ article:w->unit:n - - + + - - -articleean - - -articleean - - -id -INT -PK - - -article_id -INT -FK - - -ean -NVARCHAR(50) + + +categoryarticle + + +categoryarticle + + +id +INT +PK + + +category_id +INT +FK + + +article_id +INT +FK - - -articleean:sw->article:n - - - + + +categoryarticle:sw->category:n + + + + + + + + +categoryarticle:sw->article:n + + + - + articlelistarticle - - -articlelistarticle - - -id -INT -PK - - -article_id -INT -FK - - -articlelist_id -INT -FK - - -count -INT - - -sort -INT + + +articlelistarticle + + +id +INT +PK + + +article_id +INT +FK + + +articlelist_id +INT +FK + + +count +INT + + +sort +INT articlelistarticle:sw->article:n - - + + @@ -933,51 +968,51 @@ articlelistarticle:sw->articlelist:n - - + + - + optionslistarticle - - -optionslistarticle - - -id -INT -PK - - -article_id -INT -FK - - -optionslist_id -INT -FK - - -count -INT - - -sort -INT - - -mandated -BIT + + +optionslistarticle + + +id +INT +PK + + +article_id +INT +FK + + +optionslist_id +INT +FK + + +count +INT + + +sort +INT + + +mandated +BIT -optionslistarticle:sw->article:n +optionslistarticle:w->article:n - - + + @@ -985,134 +1020,134 @@ optionslistarticle:sw->optionslist:n - - + + - + categorypic - - -categorypic - - -id -INT -PK - - -category_id -INT -FK - - -pic_id -INT -FK - - -sort -INT + + +categorypic + + +id +INT +PK + + +category_id +INT +FK + + +pic_id +INT +FK + + +sort +INT categorypic:w->category:n - - + + - + pic - - - - - -pic - - -id -INT -PK - - -w -INT - - -h -INT - - -size -BIGINT - - -hash -NVARCHAR(64) - - -thumbw -INT - - -thumbh -INT - - -thumbhash -NVARCHAR(64) - - -source -NVARCHAR(MAX) + + + + + +pic + + +id +INT +PK + + +w +INT + + +h +INT + + +size +BIGINT + + +hash +NVARCHAR(64) + + +thumbw +INT + + +thumbh +INT + + +thumbhash +NVARCHAR(64) + + +source +NVARCHAR(MAX) categorypic:se->pic:n - - + + - + articlepic - - -articlepic - - -id -INT -PK - - -article_id -INT -FK - - -pic_id -INT -FK - - -sort -INT + + +articlepic + + +id +INT +PK + + +article_id +INT +FK + + +pic_id +INT +FK + + +sort +INT articlepic:w->article:n - - + + @@ -1120,43 +1155,43 @@ articlepic:sw->pic:n - - + + - + brandpic - - -brandpic - - -id -INT -PK - - -brand_id -INT -FK - - -pic_id -INT -FK - - -sort -INT + + +brandpic + + +id +INT +PK + + +brand_id +INT +FK + + +pic_id +INT +FK + + +sort +INT brandpic:sw->brand:n - - + + @@ -1164,52 +1199,52 @@ brandpic:sw->pic:n - - + + - + price - - -price - - -id -INT -PK - - -customergroup_id -INT -FK - - -tax_id -INT -FK - - -article_id -INT -FK - - -minmultiplier -DECIMAL(18,4) - - -net -FLOAT + + +price + + +id +INT +PK + + +customergroup_id +INT +FK + + +tax_id +INT +FK + + +article_id +INT +FK + + +minmultiplier +DECIMAL(18,4) + + +net +FLOAT price:sw->customergroup:n - - + + @@ -1217,8 +1252,8 @@ price:e->article:n - - + + @@ -1226,89 +1261,89 @@ price:sw->tax:n - - + + - + manifest - - - -manifest - - -id -INT -PK - - -number -NVARCHAR(100) - - -type -NVARCHAR(100) - - -date -DATETIME2 + + + +manifest + + +id +INT +PK + + +number +NVARCHAR(100) + + +type +NVARCHAR(100) + + +date +DATETIME2 - + manifestarticle - - -manifestarticle - - -id -INT -PK - - -tax_id -INT -FK - - -manifest_id -INT -FK - - -article_id -INT -FK - - -amount -FLOAT - - -net -FLOAT - - -transactedamount -FLOAT - - -comment? -NVARCHAR(MAX) - - -rebate -FLOAT + + +manifestarticle + + +id +INT +PK + + +tax_id +INT +FK + + +manifest_id +INT +FK + + +article_id +INT +FK + + +amount +FLOAT + + +net +FLOAT + + +transactedamount +FLOAT + + +comment? +NVARCHAR(MAX) + + +rebate +FLOAT manifestarticle:e->article:n - - + + @@ -1316,8 +1351,8 @@ manifestarticle:sw->tax:n - - + + @@ -1325,38 +1360,38 @@ manifestarticle:sw->manifest:n - - + + - + __legend - - - -Legend - -PK - -primary key - -FK - -foreign key - -? - -nullable column - -— - -FOREIGN KEY constraint - -- - - -naming convention only, no constraint + + + +Legend + +PK + +primary key + +FK + +foreign key + +? + +nullable column + +— + +FOREIGN KEY constraint + +- - + +naming convention only, no constraint diff --git a/scripts/test-api.js b/scripts/test-api.js index 23d470e..a7bfefc 100644 --- a/scripts/test-api.js +++ b/scripts/test-api.js @@ -98,6 +98,7 @@ const MENU = { { value: 'category.createUnderParent', label: 'createUnderParent', hint: 'googleAuthId, parentId, name → row' }, { value: 'category.delete', label: 'delete', hint: 'googleAuthId, id' }, { value: 'category.getTreeForCompany', label: 'getTreeForCompany', hint: 'googleAuthId, companyId → rows' }, + { value: 'category.getCategoryArticles', label: 'getCategoryArticles', hint: 'googleAuthId, categoryId → rows' }, ], }, companyuser: { @@ -340,6 +341,19 @@ async function runMethod(client, action) { await client.category.getTreeForCompany(Number(googleAuthId), Number(companyId)), ]; } + case 'category.getCategoryArticles': { + const googleAuthId = await askInt('google_auth id'); + if (googleAuthId == null) return; + const categoryId = await askInt('category id'); + if (categoryId == null) return; + return [ + 'rows', + await client.category.getCategoryArticles( + Number(googleAuthId), + Number(categoryId), + ), + ]; + } case 'companyuser.add': { const companyId = await askInt('Company id'); if (companyId == null) return; diff --git a/src/index.js b/src/index.js index 2ecce9e..973a245 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import companyUpdate from './store/company/update.js'; import companyDelete from './store/company/delete.js'; import companyList from './store/company/list.js'; import categoryGetTreeForCompany from './store/category/getTreeForCompany.js'; +import categoryGetCategoryArticles from './store/category/getCategoryArticles.js'; import categoryCreateUnderParent from './store/category/createUnderParent.js'; import categoryDelete from './store/category/delete.js'; import langCreate from './store/lang/create.js'; @@ -44,6 +45,7 @@ export default class LibDashStore { this.category = { getTreeForCompany: categoryGetTreeForCompany(pool), + getCategoryArticles: categoryGetCategoryArticles(pool), createUnderParent: categoryCreateUnderParent(pool), delete: categoryDelete(pool), }; diff --git a/src/schema.js b/src/schema.js index f23fc45..531e381 100644 --- a/src/schema.js +++ b/src/schema.js @@ -518,6 +518,21 @@ BEGIN END `; +export const INIT_SYNCPOS = ` +IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'syncpos') +BEGIN + CREATE TABLE syncpos ( + id INT IDENTITY(1,1) PRIMARY KEY, + company_id INT NOT NULL, + paircode NVARCHAR(50) NOT NULL, + token NVARCHAR(255) NULL, + CONSTRAINT FK_syncpos_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE, + CONSTRAINT UQ_syncpos_paircode UNIQUE (paircode), + CONSTRAINT UQ_syncpos_token UNIQUE (token) + ); +END +`; + /** DDL scripts in dependency order for schema init. */ export const SCHEMA_SCRIPTS = [ INIT_META, @@ -552,4 +567,5 @@ export const SCHEMA_SCRIPTS = [ INIT_NUMBERS, INIT_GET_NEXT_NUMBER_WITH_PREFIX_AND_PADDING, INIT_COMPANYUSER, + INIT_SYNCPOS, ]; diff --git a/src/sql/category.js b/src/sql/category.js index 93cfd31..bac6fed 100644 --- a/src/sql/category.js +++ b/src/sql/category.js @@ -31,7 +31,7 @@ LEFT JOIN pic p ON p.id = first_pic.pic_id ORDER BY t.sort, t.id `; -export const GET_ROOT_CATEGORY_ARTICLES = ` +export const GET_CATEGORY_ARTICLES = ` SELECT a.id, a.sku, @@ -79,7 +79,7 @@ OUTER APPLY ( ORDER BY ap.sort ASC, ap.id ASC ) first_pic LEFT JOIN pic ON pic.id = first_pic.pic_id -WHERE ca.category_id = @rootCategoryId +WHERE ca.category_id = @categoryId ORDER BY a.id `; @@ -111,6 +111,7 @@ SELECT r.rootCategoryId, co.id AS companyId, co.default_language_id AS languageId, + co.poscustomergroup_id AS posCustomerGroupId, cu.id AS companyuserId FROM category p LEFT JOIN root r ON 1 = 1 diff --git a/src/sql/purge.js b/src/sql/purge.js index 71546b6..c2e6527 100644 --- a/src/sql/purge.js +++ b/src/sql/purge.js @@ -1,6 +1,7 @@ /** Drop order = reverse of schema create dependency order. */ export const TABLES = [ 'companyuser', + 'syncpos', 'numbers', 'manifestarticle', 'manifest', diff --git a/src/store/category/getCategoryArticles.js b/src/store/category/getCategoryArticles.js new file mode 100644 index 0000000..4c9ed6d --- /dev/null +++ b/src/store/category/getCategoryArticles.js @@ -0,0 +1,16 @@ +import resolveCategoryAccess from './resolveCategoryAccess.js'; +import queryCategoryArticles from './queryCategoryArticles.js'; + +export default function getCategoryArticles(pool) { + const access = resolveCategoryAccess(pool); + const articles = queryCategoryArticles(pool); + + return async (googleAuthId, categoryId) => { + const { languageId, posCustomerGroupId } = await access( + googleAuthId, + categoryId, + ); + + return articles({ categoryId, languageId, posCustomerGroupId }); + }; +} diff --git a/src/store/category/getTreeForCompany.js b/src/store/category/getTreeForCompany.js index 4e0fda4..0a98f92 100644 --- a/src/store/category/getTreeForCompany.js +++ b/src/store/category/getTreeForCompany.js @@ -1,11 +1,10 @@ -import { - GET_ROOT_CATEGORY_ARTICLES, - GET_TREE_FOR_COMPANY, -} from '../../sql/category.js'; +import { GET_TREE_FOR_COMPANY } from '../../sql/category.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +import queryCategoryArticles from './queryCategoryArticles.js'; export default function getTreeForCompany(pool) { const access = resolveCompanyAccess(pool); + const articles = queryCategoryArticles(pool); return async (googleAuthId, companyId) => { const { rootCategoryId, languageId, posCustomerGroupId } = await access( @@ -13,24 +12,19 @@ export default function getTreeForCompany(pool) { companyId, ); - const [treeResult, articlesResult] = await Promise.all([ + const [treeResult, articleRows] = await Promise.all([ pool .request() .input('rootId', rootCategoryId) .input('languageId', languageId) .query(GET_TREE_FOR_COMPANY), - pool - .request() - .input('rootCategoryId', rootCategoryId) - .input('languageId', languageId) - .input('posCustomerGroupId', posCustomerGroupId) - .query(GET_ROOT_CATEGORY_ARTICLES), + articles({ categoryId: rootCategoryId, languageId, posCustomerGroupId }), ]); return { languageId, tree: treeResult.recordset, - articles: articlesResult.recordset, + articles: articleRows, }; }; } diff --git a/src/store/category/queryCategoryArticles.js b/src/store/category/queryCategoryArticles.js new file mode 100644 index 0000000..6d4c6c0 --- /dev/null +++ b/src/store/category/queryCategoryArticles.js @@ -0,0 +1,14 @@ +import { GET_CATEGORY_ARTICLES } from '../../sql/category.js'; + +export default function queryCategoryArticles(pool) { + return async ({ categoryId, languageId, posCustomerGroupId }) => { + const result = await pool + .request() + .input('categoryId', categoryId) + .input('languageId', languageId) + .input('posCustomerGroupId', posCustomerGroupId) + .query(GET_CATEGORY_ARTICLES); + + return result.recordset; + }; +} diff --git a/src/store/category/resolveCategoryAccess.js b/src/store/category/resolveCategoryAccess.js index 00c8a17..f919da5 100644 --- a/src/store/category/resolveCategoryAccess.js +++ b/src/store/category/resolveCategoryAccess.js @@ -23,6 +23,7 @@ export default function resolveCategoryAccess(pool) { companyId: row.companyId, rootCategoryId: row.rootCategoryId, languageId: row.languageId, + posCustomerGroupId: row.posCustomerGroupId ?? null, }; }; }