complete the ticket intervention function
parent
07e03395f3
commit
a8c474b346
|
@ -104,9 +104,9 @@ api = falcon.App(middleware=[cors.middleware, MultipartMiddleware()])
|
||||||
# Get Ticket Type
|
# Get Ticket Type
|
||||||
api.add_route('/ticket/types',
|
api.add_route('/ticket/types',
|
||||||
ticket.TicketTypeCollection())
|
ticket.TicketTypeCollection())
|
||||||
# Get Ticket List: all
|
# Get Ticket List: My Apply
|
||||||
api.add_route('/ticket/list',
|
api.add_route('/ticket/list/apply',
|
||||||
ticket.TicketListCollection())
|
ticket.TicketApplicationListCollection())
|
||||||
|
|
||||||
# Apply One Ticket
|
# Apply One Ticket
|
||||||
api.add_route('/ticket/apply/{id_}',
|
api.add_route('/ticket/apply/{id_}',
|
||||||
|
@ -116,6 +116,15 @@ api.add_route('/ticket/apply/{id_}',
|
||||||
api.add_route('/ticket/list/agent',
|
api.add_route('/ticket/list/agent',
|
||||||
ticket.TicketAgentListCollection())
|
ticket.TicketAgentListCollection())
|
||||||
|
|
||||||
|
|
||||||
|
# Get Ticket List: My Relation
|
||||||
|
api.add_route('/ticket/list/completed',
|
||||||
|
ticket.TicketCompletedListCollection())
|
||||||
|
|
||||||
|
# Get Ticket List: Has Intervention Auth And My Relation: Only admin
|
||||||
|
api.add_route('/ticket/list/intervention',
|
||||||
|
ticket.TicketInterventionListCollection())
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
# Routes for System Core
|
# Routes for System Core
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
|
@ -66,7 +66,7 @@ class TicketTypeCollection:
|
||||||
resp.text = json.dumps(result)
|
resp.text = json.dumps(result)
|
||||||
|
|
||||||
|
|
||||||
class TicketListCollection:
|
class TicketApplicationListCollection:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __init__():
|
def __init__():
|
||||||
""""Initializes ContactCollection"""
|
""""Initializes ContactCollection"""
|
||||||
|
@ -437,6 +437,230 @@ class TicketAgentListCollection:
|
||||||
resp.text = json.dumps(result)
|
resp.text = json.dumps(result)
|
||||||
|
|
||||||
|
|
||||||
|
class TicketCompletedListCollection:
|
||||||
|
@staticmethod
|
||||||
|
def __init__():
|
||||||
|
""""Initializes ContactCollection"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_options(req, resp):
|
||||||
|
resp.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_post(req, resp):
|
||||||
|
|
||||||
|
try:
|
||||||
|
raw_json = req.stream.read().decode('utf-8')
|
||||||
|
except Exception as ex:
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex)
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"user_name": "admin",
|
||||||
|
}"""
|
||||||
|
new_values = json.loads(raw_json)
|
||||||
|
|
||||||
|
checked_fields = [
|
||||||
|
{
|
||||||
|
"name": "user_name",
|
||||||
|
"type": str
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
for field in checked_fields:
|
||||||
|
_name = field['name']
|
||||||
|
_type = field['type']
|
||||||
|
if _name not in new_values.keys() or \
|
||||||
|
not isinstance(new_values[_name], _type) or \
|
||||||
|
len(str(new_values[_name])) == 0:
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_FIELD' + _name)
|
||||||
|
|
||||||
|
payload = new_values
|
||||||
|
user_name = payload['user_name']
|
||||||
|
|
||||||
|
cnx = mysql.connector.connect(**config.loonflow)
|
||||||
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
|
# Get Ticket ids: Completed
|
||||||
|
query = (" SELECT id, ticket_id "
|
||||||
|
" FROM ticket_ticketuser "
|
||||||
|
" WHERE username = %s"
|
||||||
|
" ORDER BY id DESC ")
|
||||||
|
cursor.execute(query, (user_name,))
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
ticket_ids = []
|
||||||
|
if rows is not None and len(rows) > 0:
|
||||||
|
for row in rows:
|
||||||
|
ticket_id = row[1]
|
||||||
|
if ticket_id not in ticket_ids:
|
||||||
|
ticket_ids.append(ticket_id)
|
||||||
|
|
||||||
|
query = (" SELECT id, name "
|
||||||
|
" FROM workflow_workflow "
|
||||||
|
" ORDER BY id ")
|
||||||
|
cursor.execute(query)
|
||||||
|
workflow_rows = cursor.fetchall()
|
||||||
|
|
||||||
|
workflow_result = {}
|
||||||
|
if workflow_rows is not None and len(workflow_rows) > 0:
|
||||||
|
for row in workflow_rows:
|
||||||
|
workflow_result[row[0]] = row[1]
|
||||||
|
|
||||||
|
query = (" SELECT id, name "
|
||||||
|
" FROM workflow_state "
|
||||||
|
" ORDER BY id ")
|
||||||
|
cursor.execute(query)
|
||||||
|
workflow_state_rows = cursor.fetchall()
|
||||||
|
|
||||||
|
workflow_state_result = {}
|
||||||
|
if workflow_state_rows is not None and len(workflow_state_rows) > 0:
|
||||||
|
for row in workflow_state_rows:
|
||||||
|
workflow_state_result[row[0]] = row[1]
|
||||||
|
|
||||||
|
query = (" SELECT id, title, workflow_id, sn, state_id, creator, gmt_created, gmt_modified "
|
||||||
|
" FROM ticket_ticketrecord "
|
||||||
|
" ORDER BY id DESC ")
|
||||||
|
cursor.execute(query, )
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
cursor.close()
|
||||||
|
cnx.close()
|
||||||
|
|
||||||
|
result = list()
|
||||||
|
if rows is not None and len(rows) > 0:
|
||||||
|
for row in rows:
|
||||||
|
_id = row[0]
|
||||||
|
if _id not in ticket_ids:
|
||||||
|
continue
|
||||||
|
meta_result = {"id": row[0],
|
||||||
|
"title": row[1],
|
||||||
|
"ticket_type": workflow_result.get(row[2]),
|
||||||
|
"sn": row[3],
|
||||||
|
"state": workflow_state_result.get(row[4]),
|
||||||
|
"creator": row[5],
|
||||||
|
"gmt_created": str(row[6]),
|
||||||
|
"gmt_modified": str(row[7])
|
||||||
|
}
|
||||||
|
result.append(meta_result)
|
||||||
|
|
||||||
|
resp.text = json.dumps(result)
|
||||||
|
|
||||||
|
|
||||||
|
class TicketInterventionListCollection:
|
||||||
|
@staticmethod
|
||||||
|
def __init__():
|
||||||
|
""""Initializes ContactCollection"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_options(req, resp):
|
||||||
|
resp.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_post(req, resp):
|
||||||
|
|
||||||
|
try:
|
||||||
|
raw_json = req.stream.read().decode('utf-8')
|
||||||
|
except Exception as ex:
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex)
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"user_name": "admin",
|
||||||
|
}"""
|
||||||
|
new_values = json.loads(raw_json)
|
||||||
|
|
||||||
|
checked_fields = [
|
||||||
|
{
|
||||||
|
"name": "user_name",
|
||||||
|
"type": str
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
for field in checked_fields:
|
||||||
|
_name = field['name']
|
||||||
|
_type = field['type']
|
||||||
|
if _name not in new_values.keys() or \
|
||||||
|
not isinstance(new_values[_name], _type) or \
|
||||||
|
len(str(new_values[_name])) == 0:
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||||
|
description='API.INVALID_FIELD' + _name)
|
||||||
|
|
||||||
|
payload = new_values
|
||||||
|
user_name = payload['user_name']
|
||||||
|
|
||||||
|
if user_name != 'admin':
|
||||||
|
raise falcon.HTTPError(falcon.HTTP_401, title='API.UNAUTHENTICATED',
|
||||||
|
description='API.INVALID_FIELD' + user_name)
|
||||||
|
|
||||||
|
cnx = mysql.connector.connect(**config.loonflow)
|
||||||
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
|
# Get Ticket ids: Completed
|
||||||
|
query = (" SELECT id, ticket_id "
|
||||||
|
" FROM ticket_ticketuser "
|
||||||
|
" WHERE username = %s "
|
||||||
|
" ORDER BY id DESC ")
|
||||||
|
cursor.execute(query, (user_name,))
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
ticket_ids = []
|
||||||
|
if rows is not None and len(rows) > 0:
|
||||||
|
for row in rows:
|
||||||
|
ticket_id = row[1]
|
||||||
|
if ticket_id not in ticket_ids:
|
||||||
|
ticket_ids.append(ticket_id)
|
||||||
|
|
||||||
|
query = (" SELECT id, name "
|
||||||
|
" FROM workflow_workflow "
|
||||||
|
" ORDER BY id ")
|
||||||
|
cursor.execute(query)
|
||||||
|
workflow_rows = cursor.fetchall()
|
||||||
|
|
||||||
|
workflow_result = {}
|
||||||
|
if workflow_rows is not None and len(workflow_rows) > 0:
|
||||||
|
for row in workflow_rows:
|
||||||
|
workflow_result[row[0]] = row[1]
|
||||||
|
|
||||||
|
query = (" SELECT id, name "
|
||||||
|
" FROM workflow_state "
|
||||||
|
" ORDER BY id ")
|
||||||
|
cursor.execute(query)
|
||||||
|
workflow_state_rows = cursor.fetchall()
|
||||||
|
|
||||||
|
workflow_state_result = {}
|
||||||
|
if workflow_state_rows is not None and len(workflow_state_rows) > 0:
|
||||||
|
for row in workflow_state_rows:
|
||||||
|
workflow_state_result[row[0]] = row[1]
|
||||||
|
|
||||||
|
query = (" SELECT id, title, workflow_id, sn, state_id, creator, gmt_created, gmt_modified "
|
||||||
|
" FROM ticket_ticketrecord "
|
||||||
|
" ORDER BY id DESC ")
|
||||||
|
cursor.execute(query, )
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
cursor.close()
|
||||||
|
cnx.close()
|
||||||
|
|
||||||
|
result = list()
|
||||||
|
if rows is not None and len(rows) > 0:
|
||||||
|
for row in rows:
|
||||||
|
_id = row[0]
|
||||||
|
if _id not in ticket_ids:
|
||||||
|
continue
|
||||||
|
meta_result = {"id": row[0],
|
||||||
|
"title": row[1],
|
||||||
|
"ticket_type": workflow_result.get(row[2]),
|
||||||
|
"sn": row[3],
|
||||||
|
"state": workflow_state_result.get(row[4]),
|
||||||
|
"creator": row[5],
|
||||||
|
"gmt_created": str(row[6]),
|
||||||
|
"gmt_modified": str(row[7])
|
||||||
|
}
|
||||||
|
result.append(meta_result)
|
||||||
|
|
||||||
|
resp.text = json.dumps(result)
|
||||||
|
|
||||||
|
|
||||||
class ContactItem:
|
class ContactItem:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __init__():
|
def __init__():
|
||||||
|
|
|
@ -109,7 +109,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isResponseOK = false;
|
let isResponseOK = false;
|
||||||
// Get Ticket List
|
// Get Ticket List
|
||||||
fetch(APIBaseURL + '/ticket/list', {
|
fetch(APIBaseURL + '/ticket/list/apply', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json'
|
'Content-type': 'application/json'
|
||||||
|
|
|
@ -100,12 +100,14 @@ const TicketIntervention = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isResponseOK = false;
|
let isResponseOK = false;
|
||||||
// Get Ticket List
|
// Get Ticket List
|
||||||
fetch(APIBaseURL + '/ticket/list', {
|
fetch(APIBaseURL + '/ticket/list/intervention', {
|
||||||
method: 'GET',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json'
|
'Content-type': 'application/json'
|
||||||
},
|
},
|
||||||
body: null
|
body: JSON.stringify({
|
||||||
|
user_name: 'admin'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
|
@ -100,12 +100,14 @@ const TicketList = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isResponseOK = false;
|
let isResponseOK = false;
|
||||||
// Get Ticket List
|
// Get Ticket List
|
||||||
fetch(APIBaseURL + '/ticket/list', {
|
fetch(APIBaseURL + '/ticket/list/completed', {
|
||||||
method: 'GET',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json'
|
'Content-type': 'application/json'
|
||||||
},
|
},
|
||||||
body: null
|
body: JSON.stringify({
|
||||||
|
user_name: 'admin'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
@ -129,16 +131,6 @@ const TicketList = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
|
|
||||||
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
|
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
|
||||||
|
|
||||||
const nameFormatter = (dataField, { name }) => (
|
|
||||||
<Link to="#">
|
|
||||||
<Media tag={Flex} align="center">
|
|
||||||
<Media body className="ml-2">
|
|
||||||
<h5 className="mb-0 fs--1">{name}</h5>
|
|
||||||
</Media>
|
|
||||||
</Media>
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
|
|
||||||
const actionFormatter = (dataField, { id }) => (
|
const actionFormatter = (dataField, { id }) => (
|
||||||
// Control your row with this id
|
// Control your row with this id
|
||||||
<UncontrolledDropdown>
|
<UncontrolledDropdown>
|
||||||
|
|
Loading…
Reference in New Issue