Skip to content

Commit

Permalink
add userid to stats query (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
eve-git authored Oct 20, 2023
1 parent 4ec58a1 commit 5e6cee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.34'
__version__ = '1.1.35'
14 changes: 10 additions & 4 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,10 @@ class Stats(Resource):
@jwt.requires_auth
def get(*args, **kwargs):

user = None
if bool(request.args.get('myStats', False)):
user = get_or_create_user_by_jwt(g.jwt_oidc_token_info)

# default is last 1 hour, but can be sent as parameter
timespan = int(request.args.get('timespan', 1))

Expand All @@ -1562,9 +1566,11 @@ def get(*args, **kwargs):
return jsonify({'message': 'paging parameters were not integers'}), 406

q = RequestDAO.query \
.filter(RequestDAO.stateCd.in_(State.COMPLETED_STATE))\
.filter(RequestDAO.lastUpdate >= text('(now() at time zone \'utc\') - INTERVAL \'{delay} HOURS\''.format(delay=timespan))) \
.order_by(RequestDAO.lastUpdate.desc())
.filter(RequestDAO.stateCd.in_(State.COMPLETED_STATE)) \
.filter(RequestDAO.lastUpdate >= text('(now() at time zone \'utc\') - INTERVAL \'{delay} HOURS\''.format(delay=timespan)))
if user:
q = q.filter(RequestDAO.userId == user.id)
q = q.order_by(RequestDAO.lastUpdate.desc())

count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = db.session.execute(count_q).scalar()
Expand All @@ -1580,7 +1586,7 @@ def get(*args, **kwargs):
requests = q.all()
rep = {
'numRecords': count,
'nameRequests': request_search_schemas.dump(requests)[0]
'nameRequests': request_search_schemas.dump(requests)
}
return jsonify(rep)

Expand Down

0 comments on commit 5e6cee7

Please sign in to comment.