diff --git a/api/items.js b/api/items.js index f7dab90..6b4fbe4 100644 --- a/api/items.js +++ b/api/items.js @@ -50,6 +50,10 @@ router.post('/', ensureAdmin, parseJSON, itemValidators, async (req, res) => { router.get('/by-slug/:slug', async (req, res) => { const item = await db.item.findBySlug(req.params.slug); + + if(!item.published) + return res.json(null) + res.json(item) }) diff --git a/db/sql/2-views.sql b/db/sql/2-views.sql index e23fcac..09434b3 100644 --- a/db/sql/2-views.sql +++ b/db/sql/2-views.sql @@ -74,7 +74,8 @@ create or replace view sos.v_category as ) child_item_counts on "child_category".category_uuid = "child_item_counts".category_uuid left join sos."category" "parent_category" on "parent_category_link".category_category_parent_uuid = "parent_category".category_uuid left join sos."category_item" on "category".category_uuid = "category_item".category_item_category_uuid - left join sos.v_item on "category_item".category_item_item_uuid = item_uuid; + left join sos.v_item on "category_item".category_item_item_uuid = item_uuid + where item_published = true; create or replace view sos.v_cart_price as select cart_uuid, diff --git a/pages/admin/shipments/new.js b/pages/admin/shipments/new.js index a009a90..b54001a 100644 --- a/pages/admin/shipments/new.js +++ b/pages/admin/shipments/new.js @@ -9,7 +9,7 @@ import axios from 'axios' import router from 'next/router' NewShipment.getInitialProps = async ({ctx: {axios}}) => { - const {data: allItems} = await axios.get('/api/items') + const {data: allItems} = await axios.get('/api/items?showUnpublished=true') return {allItems} }