Can update category details

main
Ashelyn Dawn 4 years ago
parent a3462f65aa
commit 3db816eb29

@ -12,7 +12,7 @@ router.get('/', async (req, res) => {
router.get('/by-slug/:slug', async (req, res) => {
const category = await db.category.findBySlug(req.params.slug)
res.json(category)
})
@ -32,6 +32,17 @@ router.post('/', parseJSON, newCategoryValidators, async (req, res) => {
res.json(category)
})
router.post('/:uuid', parseJSON, newCategoryValidators, async (req, res) => {
const category = await db.category.update(
req.params.uuid,
req.body.name,
req.body.urlslug,
req.body.description
)
res.json(category)
})
router.put('/:category_uuid/items/:item_uuid', async (req, res) => {
const category = await db.category.addItem(req.params.category_uuid, req.params.item_uuid);
res.json(category)

@ -2,6 +2,7 @@ const pg = require('../pg')
const joinjs = require('join-js').default;
const debug = require('debug')('sos:db:category')
const mappings = require('../mappings')
const dbUtil = require('../util')
const category = module.exports = {}
@ -87,3 +88,15 @@ category.addCategory = async (parent_uuid, child_uuid) => {
return joinjs.map(rows, mappings, 'categoryMap', 'category_')[0];
}
category.update = async (uuid, name, urlslug, description) =>
dbUtil.executeFunction({
name: 'update_category',
params: [
uuid,
name,
urlslug,
description
],
returnType: 'category',
single: true
})

@ -235,6 +235,25 @@ begin
return query select * from sos.v_category where category_uuid = _category_uuid;
end; $function$;
create or replace function sos.update_category(_category_uuid uuid, _category_name text, _category_urlslug citext, _category_description text)
returns setof sos.v_category
language plpgsql
as $function$
begin
update sos."category" set (
category_name,
category_urlslug,
category_description
) = (
_category_name,
_category_urlslug,
_category_description
) where category_uuid = _category_uuid;
return query select * from sos.v_category where category_uuid = _category_uuid;
end; $function$;
create or replace function sos.add_item_to_category(_category_uuid uuid, _item_uuid uuid)
returns setof sos.v_category
language plpgsql

@ -30,9 +30,6 @@ export default function Editcategory({category}) {
<RMWCButton outlined onClick={()=>router.push(`/admin/categories/${category.urlslug}/items`)}>Edit Items ({category.items.length})</RMWCButton>
<RMWCButton outlined onClick={()=>router.push(`/admin/categories/${category.urlslug}/children`)}>Edit Child Categories ({category.children.length})</RMWCButton>
</ActionBar>
<p className="warning">
This is only half finished . . . you can make new stuff but editing doesn't work yet.
</p>
<FormController url={`/api/categories/${category.uuid}`} afterSubmit={afterUpdate}>
<Input name="name" initialValue={category.name} validate={stringLengthAtLeastOne} />
<TextArea name="description" initialValue={category.description} validate={stringLengthAtLeastOne} />

Loading…
Cancel
Save