From 02ecd49e85c113d4673231386eee683ee07a73bd Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 4 Jan 2023 18:28:14 +0000 Subject: [PATCH] Return member's name on pinball card scan --- apiserver/apiserver/api/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index d323df9..450c1c6 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -1326,6 +1326,21 @@ class PinballViewSet(Base): return Response(200) + @action(detail=True, methods=['get']) + def get_name(self, request, pk=None): + auth_token = request.META.get('HTTP_AUTHORIZATION', '') + if secrets.PINBALL_API_TOKEN and auth_token != 'Bearer ' + secrets.PINBALL_API_TOKEN: + raise exceptions.PermissionDenied() + + card = get_object_or_404(models.Card, card_number=pk) + member = card.user.member + + res = dict( + name=member.preferred_name + ' ' + member.last_name[0] + ) + return Response(res) + + class RegistrationView(RegisterView): serializer_class = serializers.MyRegisterSerializer