(categoryId)
| 90 | |
| 91 | // create or retrieve category |
| 92 | async function fetchCategory(categoryId) { |
| 93 | let newCat = null; |
| 94 | const category = { name: categoryId, level: 'USER' }; |
| 95 | try { |
| 96 | newCat = await models.Category.create(category); |
| 97 | } catch (err) { |
| 98 | try { |
| 99 | newCat = await models.Category.findOne({ where: { name: categoryId } }); |
| 100 | } catch (err) { |
| 101 | return { newCat: null, err }; |
| 102 | } |
| 103 | } |
| 104 | return { category: newCat, err: null }; |
| 105 | } |
| 106 | |
| 107 | // Create |
| 108 | router.post('', authenticate, async (req, res) => { |