Skip to content

Commit

Permalink
Cleanup ticketid to hash
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno committed Feb 20, 2025
1 parent 6757aff commit 38c3426
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions backend/api/participants/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def participant(info: Info, id: strawberry.ID, conference: str) -> Participant |


@strawberry.field
def ticket_id_to_user_hashid(
ticket_id: strawberry.ID, conference_code: str
) -> str | None:
def ticket_id_to_hashid(ticket_id: strawberry.ID, conference_code: str) -> str | None:
conference = Conference.objects.filter(code=conference_code).first()
decoded_ticket_id = decode_hashid(ticket_id)
order_position = pretix.get_order_position(conference, decoded_ticket_id)
Expand All @@ -43,8 +41,10 @@ def ticket_id_to_user_hashid(
if not attendee_user:
return None

user_id = attendee_user.id
return encode_hashid(int(user_id), salt=settings.USER_ID_HASH_SALT, min_length=6)
participant = ParticipantModel.objects.filter(
conference=conference, user=attendee_user
).first()
return participant.hashid


# TODO: move this to a badge app :)
Expand Down Expand Up @@ -81,5 +81,5 @@ def conference_role_for_ticket_data(

ParticipantQueries = create_type(
"ParticipantQueries",
(participant, ticket_id_to_user_hashid, conference_role_for_ticket_data),
(participant, ticket_id_to_hashid, conference_role_for_ticket_data),
)
8 changes: 4 additions & 4 deletions frontend/src/pages/b/[hashid].tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { GetServerSideProps } from "next";

import { getApolloClient } from "~/apollo/client";
import { queryTicketIdToUserHashid } from "~/types";
import { queryTicketIdToHashid } from "~/types";

export const getServerSideProps: GetServerSideProps = async ({
req,
params,
}) => {
const hashid = params.hashid as string;
const client = getApolloClient(null, req.cookies);
const result = await queryTicketIdToUserHashid(client, {
const result = await queryTicketIdToHashid(client, {
ticketId: hashid,
conference: process.env.conferenceCode,
});

if (result.data?.ticketIdToUserHashid) {
if (result.data?.ticketIdToHashid) {
return {
redirect: {
destination: `/profile/${result.data.ticketIdToUserHashid}`,
destination: `/profile/${result.data.ticketIdToHashid}`,
permanent: false,
},
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/b/query.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
query TicketIdToUserHashid($ticketId: ID!, $conference: String!) {
ticketIdToUserHashid(ticketId: $ticketId, conferenceCode: $conference)
query TicketIdToHashid($ticketId: ID!, $conference: String!) {
ticketIdToHashid(ticketId: $ticketId, conferenceCode: $conference)
}

0 comments on commit 38c3426

Please sign in to comment.