Can delete items and images

main
Ashelyn Dawn 5 years ago
parent 8ba501eac6
commit ea28458ff6

@ -8,4 +8,9 @@ router.get('/:uuid/:size', async (req, res) => {
res.end(image.file)
})
router.delete('/:uuid', async (req, res) => {
const item = await db.item.removeImage(req.params.uuid)
res.json(item)
})
module.exports = router

@ -9,7 +9,7 @@ const upload = require('multer')({
storage: require('multer').memoryStorage(),
limits: {
files: 1,
fileSize: 500000
fileSize: 3000000
}
})
@ -44,10 +44,15 @@ router.post('/', parseJSON, newItemValidators, async (req, res) => {
res.json(item)
})
router.delete('/:uuid', async (req, res) => {
const result = await db.item.removeItem(req.params.uuid)
res.json({deleted: true})
})
router.post('/:uuid/images', upload.single('image'), async (req, res) => {
// TODO: Use the real user when we have authentication
req.user = {
uuid: '5e17388d-612b-4ea8-b76d-620a7bb24824'
uuid: '56881ad0-8d80-496a-b036-aed03d0895ce'
}
// Handle either image upload body or JSON body

@ -106,3 +106,27 @@ item.getImage = async (image_uuid, size) => {
const {rows} = await pg.query(query)
return joinjs.map(rows, mappings, 'bareImageMap', 'image_')[0];
}
item.removeImage = async (image_uuid) => {
const query = {
text: 'select * from public.delete_image($1)',
values: [
image_uuid
]
}
const {rows} = await pg.query(query)
return joinjs.map(rows, mappings, 'itemMap', 'item_')[0]
}
item.removeItem = async (item_uuid) => {
const query = {
text: 'select * from public.delete_item($1)',
values: [
item_uuid
]
}
const {rows} = await pg.query(query)
return joinjs.map(rows, mappings, 'itemMap', 'item_')[0]
}

@ -24,19 +24,6 @@ create or replace view public.v_cart as
left join "cart_item" on "cart".cart_uuid = "cart_item".cart_item_cart_uuid
left join "item" on "cart_item".cart_item_item_uuid = "item".item_uuid;
create or replace view public.v_category as
select
"category".*,
"child_category".category_uuid as child_category_uuid,
"child_category".category_name as child_category_name,
"child_category".category_urlslug as child_category_urlslug,
"item".*
from "category"
left join "category_category" on "category".category_uuid = "category_category".category_category_parent_uuid
left join "category" "child_category" on "category_category".category_category_child_uuid = "child_category".category_uuid
left join "category_item" on "category".category_uuid = "category_item".category_item_category_uuid
left join "item" on "category_item".category_item_item_uuid = "item".item_uuid;
create or replace view public.v_item as
select
"item".*,
@ -52,7 +39,12 @@ create or replace view public.v_item as
create or replace view public.v_category as
select
"category".*,
"child_category".category_uuid as child_category_uuid,
"child_category".category_name as child_category_name,
"child_category".category_urlslug as child_category_urlslug,
v_item.*
from "category"
left join "category_item" on "category_item".category_item_category_uuid = "category".category_uuid
left join "category_category" on "category".category_uuid = "category_category".category_category_parent_uuid
left join "category" "child_category" on "category_category".category_category_child_uuid = "child_category".category_uuid
left join "category_item" on "category".category_uuid = "category_item".category_item_category_uuid
left join v_item on "category_item".category_item_item_uuid = item_uuid;
Loading…
Cancel
Save