mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 22:42:28 -05:00
Add check org name is unique endpoint
This commit is contained in:
@@ -107,3 +107,26 @@ def get_organisation_users(organisation_id):
|
||||
|
||||
result = user_schema.dump(org_users, many=True)
|
||||
return jsonify(data=result.data)
|
||||
|
||||
|
||||
@organisation_blueprint.route('/unique', methods=["GET"])
|
||||
def is_organisation_name_unique():
|
||||
organisation_id, name = check_request_args(request)
|
||||
|
||||
name_exists = Organisation.query.filter(Organisation.name.ilike(name)).first()
|
||||
|
||||
result = (not name_exists) or str(name_exists.id) == organisation_id
|
||||
return jsonify(result=result), 200
|
||||
|
||||
|
||||
def check_request_args(request):
|
||||
org_id = request.args.get('org_id')
|
||||
name = request.args.get('name', None)
|
||||
errors = []
|
||||
if not org_id:
|
||||
errors.append({'org_id': ["Can't be empty"]})
|
||||
if not name:
|
||||
errors.append({'name': ["Can't be empty"]})
|
||||
if errors:
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
return org_id, name
|
||||
|
||||
Reference in New Issue
Block a user