items_API.getItemLink updated to new schema
This commit is contained in:
parent
780c43cd73
commit
3c30adcd49
Binary file not shown.
Binary file not shown.
@ -147,7 +147,24 @@ def getPrefixes(site:str, payload:tuple, convert:bool=True):
|
||||
return recordset, count
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
raise postsqldb.DatabaseError(error, payload, sql)
|
||||
|
||||
|
||||
def getItemLink(site: str, payload:tuple, convert:bool=True):
|
||||
database_config = config.config()
|
||||
item_link = ()
|
||||
sql = f"SELECT * FROM {site}_itemlinks WHERE id=%s;"
|
||||
try:
|
||||
with psycopg2.connect(**database_config) as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(sql, payload)
|
||||
rows = cur.fetchone()
|
||||
if rows and convert:
|
||||
item_link = postsqldb.tupleDictionaryFactory(cur.description, rows)
|
||||
elif rows and not convert:
|
||||
item_link = rows
|
||||
return item_link
|
||||
except Exception as error:
|
||||
raise postsqldb.DatabaseError(error, payload, sql)
|
||||
|
||||
def paginateZonesBySku(site: str, payload: tuple, convert=True):
|
||||
database_config = config.config()
|
||||
zones, count = (), 0
|
||||
|
||||
@ -463,15 +463,27 @@ def getPossibleLocations():
|
||||
@items_api.route('/item/getLinkedItem', methods=["GET"])
|
||||
@login_required
|
||||
def getLinkedItem():
|
||||
""" GET itemlink from system by passing an ID
|
||||
---
|
||||
parameters:
|
||||
- in: query
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
default: 1
|
||||
required: true
|
||||
description: item link to get from the system
|
||||
responses:
|
||||
200:
|
||||
description: Item Link GET successful.
|
||||
"""
|
||||
linked_item = {}
|
||||
if request.method == "GET":
|
||||
id = int(request.args.get('id', 1))
|
||||
database_config = config()
|
||||
site_name = session['selected_site']
|
||||
with psycopg2.connect(**database_config) as conn:
|
||||
linked_item = database.__selectTuple(conn, site_name, f"{site_name}_itemlinks", (id, ), convert=True)
|
||||
linked_item = database_items.getItemLink(site_name, (id, ))
|
||||
return jsonify({'linked_item': linked_item, 'error': False, 'message': 'Linked Item added!!'})
|
||||
return jsonify({'linked_item': linked_item, 'error': True, 'message': 'These was an error with adding to the linked list!'})
|
||||
return jsonify({'linked_item': linked_item, 'error': True, 'message': f'method {request.method} not allowed'})
|
||||
|
||||
@items_api.route('/item/addLinkedItem', methods=["POST"])
|
||||
def addLinkedItem():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user