def delete(self, businessId, approvedCategory): claims = get_jwt_claims() if not claims['is_admin']: return { 'message': 'Error # 213 in Product Resource, admin prevelige required' }, 400 approved_zid_list = VbusinessModel.find_all_business_list() current_user = UserModel.find_by_user(get_jwt_identity()) if (current_user.businessId not in approved_zid_list) or (businessId not in approved_zid_list): return { 'message': 'Error # 180 in Product Resource, You have not been authorized to use this business' }, 400 if not CaitemModel.find_by_zid_category([businessId], [approvedCategory]): return { 'message': 'Error # 131 in Product Resources, this category or business ID does not exist in our System' }, 400 categoryDetail = CategoryModel.find_by_zid_category( current_user.businessId, approvedCategory) if categoryDetail: categoryDetail.delete_from_db() return { 'message': 'Response # 225 in Product Resources, Category has been deleted' }, 200
def post(self, businessId): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'admin previlege required'}, 400 approved_zid_list = VbusinessModel.find_all_business_list() current_user = UserModel.find_by_user(get_jwt_identity()) if (current_user.businessId not in approved_zid_list) or (businessId not in approved_zid_list): return { 'message': 'Error # 180 in Product Resource, You have not been authorized to use this business' }, 400 json_data = request.get_json() if not json_data: return { 'message': 'Error # 186 in Product Resource, No input data provided' }, 400 try: data = categorySchema.load(json_data).data except ValidationError as err: return err.messages, 400 data['approvedCategory'] = html.unescape(data['approvedCategory']) if not CaitemModel.find_by_zid_category([businessId], [data['approvedCategory']]): return { 'message': 'Error # 131 in Product Resources, this category or business ID does not exist in our System' }, 400 if CategoryModel.find_by_zid_category(current_user.businessId, data['approvedCategory']): return { 'message': 'Error # 194 in Product Resources, this category has already been approved' }, 400 categoryDetail = CategoryModel( zid=businessId, approvedCategory=data['approvedCategory'], xtra1=None, xtra2=None, xtra3=None, xtra4=None, xtra5=None) try: categoryDetail.save_to_db() except Exception as e: print(e) return { "message": "Error # 205 in Product Resource, An error occured while saving the product category" }, 400 return categoryDetail.json(), 200