diff --git a/app/api/categories.py b/app/api/categories.py index 07b0dd05..8e556d8c 100644 --- a/app/api/categories.py +++ b/app/api/categories.py @@ -1,5 +1,6 @@ from flask_restplus import Namespace, Resource, reqparse from flask_login import login_required, current_user +from mongoengine.errors import NotUniqueError from ..util.pagination_util import Pagination from ..util import query_util @@ -37,7 +38,7 @@ def post(self): supercategory = args.get('supercategory') metadata = args.get('metadata', {}) color = args.get('color') - + try: category = CategoryModel( name=name, @@ -46,8 +47,8 @@ def post(self): metadata=metadata ) category.save() - except (ValueError, TypeError) as e: - return {'message': str(e)}, 400 + except NotUniqueError as e: + return {'message': 'Category already exists. Check the undo tab to fully delete the category.'}, 400 return query_util.fix_ids(category) diff --git a/client/src/models/categories.js b/client/src/models/categories.js new file mode 100644 index 00000000..9d8568b9 --- /dev/null +++ b/client/src/models/categories.js @@ -0,0 +1,16 @@ +import axios from "axios"; + +const baseURL = "/api/category/"; + +export default { + allData(params) { + return axios.get(baseURL + "data", { + params: { + ...params + } + }); + }, + create(create) { + return axios.post(baseURL, { ...create }); + } +}; diff --git a/client/src/views/Categories.vue b/client/src/views/Categories.vue index be617d6e..b7e5d6c8 100755 --- a/client/src/views/Categories.vue +++ b/client/src/views/Categories.vue @@ -146,7 +146,9 @@