Commit 7309c7db authored by John Red Medrano's avatar John Red Medrano

Merge pull request #750 in RMS/api-main-service from core-dev-red-develop to RMSv2

* commit '03752474':
  {dev bugfix} added a function that return will retun error message
parents f0185150 03752474
......@@ -15,6 +15,16 @@ from app.businesslayer.changerequest.change_request_template import (
)
def error_message(code, message, status, status_code):
return Response(
{
"code": code,
"message": message,
"status": status
},
status=status_code
)
def error_safe(function):
def wrap(request, *args, **kwargs):
stat = status.HTTP_500_INTERNAL_SERVER_ERROR
......@@ -103,19 +113,22 @@ class rms:
def wrapper(self, request, *args, **kwargs):
payload = request.data
if not 'excel_code' in payload:
return Response(
{"message": "Excel code is required"}
return error_message(
'400', "Excel code is required",
'failed', status.HTTP_400_BAD_REQUEST
)
elif len(payload['excel_code'].strip()) == 0:
return Response(
{"message": "Excel code is may not be blank"}
return error_message(
'400', "Excel code is may not be blank",
'failed', status.HTTP_400_BAD_REQUEST
)
is_excel_code_exist = self.queryset.filter(
excel_code=payload['excel_code']
)
if is_excel_code_exist:
return Response(
{"message": "This excel code is already exists"}
return error_message(
'400', "This excel code is already exists",
'failed', status.HTTP_400_BAD_REQUEST
)
return function(self, request, *args, **kwargs)
return wrapper
......@@ -128,14 +141,12 @@ class rms:
payload = request.data
username = self.queryset.filter(username=payload['username'])
if username.count() >= 1:
return Response(
{
"message": f"username {username.first().username} is already taken"
},
status=status.HTTP_400_BAD_REQUEST
return error_message(
'400',
f"username {username.first().username} is already taken",
'failed',
status.HTTP_400_BAD_REQUEST
)
# rms.user_create(self, request, *args, **kwargs)
return function(self, request, *args, **kwargs)
return wrapper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment