Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Refactorización de estados de UserTicket a enums y mejora de documentación #275

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 79 additions & 11 deletions src/datasources/db/userTickets.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,82 @@
import { relations } from "drizzle-orm";
import { index, pgTable, text, uuid } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";

import { purchaseOrdersSchema, ticketsSchema, usersSchema } from "./schema";
import { createdAndUpdatedAtFields } from "./shared";

export enum UserTicketApprovalStatus {
/**
* TODO: Document the use case for this status
* This status is used when a ticket is approved by:
* - Paying the ticket from a purchase order (not created by a waitlist)
* - Calling approvalUserTicket (as a super admin or community admin)
* - Accepting a gifted ticket
*/
Approved = "approved",
/**
* TODO: Document the waitlist use case because it is not clear how to get out of this status
* The DB default value represents one of the following:
* - The ticket has been purchased but not yet paid
* - The ticket is on a waitlist
*/
Pending = "pending",
/**
* TODO: Document this status better because the use case is not clear
* The mutation acceptGiftedTicket sets the status to Approved not GiftAccepted
*/
GiftAccepted = "gift_accepted",
/**
* TODO: Document this status better and the relation with GiftAccepted if there is any
* The ticket was gifted by an admin trough retool
* the status changes to Approved when the users fills some data
* it was mainly used for the AI Hackathon 2024
*/
Gifted = "gifted",
/**
* TODO: Document use case for this status
*/
NotRequired = "not_required",
/**
* TODO: Document use case for this status
*/
Rejected = "rejected",
/**
* TODO: Document this status better because the use case is not clear
* This status is used when a ticket is cancelled by:
* - The owner of the ticket
* - A super admin
* - A event community admin
*/
Cancelled = "cancelled",
}

export const userTicketsApprovalStatusEnum = [
"approved",
"pending",
"gift_accepted",
"gifted",
"not_required",
"rejected",
"cancelled",
UserTicketApprovalStatus.Approved,
UserTicketApprovalStatus.Pending,
UserTicketApprovalStatus.GiftAccepted,
UserTicketApprovalStatus.Gifted,
UserTicketApprovalStatus.NotRequired,
UserTicketApprovalStatus.Rejected,
UserTicketApprovalStatus.Cancelled,
] as const;

export const userTicketsRedemptionStatusEnum = ["redeemed", "pending"] as const;
export enum UserTicketRedemptionStatus {
Redeemed = "redeemed",
Pending = "pending",
}

export const userTicketsRedemptionStatusEnum = [
/**
* The user has redeemed the ticket by assisting to the event
*/
UserTicketRedemptionStatus.Redeemed,
/**
* The user has not redeemed the ticket yet
*/
UserTicketRedemptionStatus.Pending,
] as const;

// USER-TICKETS-TABLE
export const userTicketsSchema = pgTable(
Expand All @@ -33,12 +94,15 @@ export const userTicketsSchema = pgTable(
approvalStatus: text("approval_status", {
enum: userTicketsApprovalStatusEnum,
})
.default("pending")
.default(UserTicketApprovalStatus.Pending)
.notNull(),
redemptionStatus: text("redemption_status", {
enum: userTicketsRedemptionStatusEnum,
enum: [
UserTicketRedemptionStatus.Redeemed,
UserTicketRedemptionStatus.Pending,
],
})
.default("pending")
.default(UserTicketRedemptionStatus.Pending)
.notNull(),
...createdAndUpdatedAtFields,
},
Expand Down Expand Up @@ -69,3 +133,7 @@ export const insertUserTicketsSchema = createInsertSchema(userTicketsSchema);
export const approveUserTicketsSchema = selectUserTicketsSchema.pick({
approvalStatus: true,
});

export type InsertUserTicketSchema = z.infer<typeof insertUserTicketsSchema>;

export type SelectUserTicketSchema = z.infer<typeof selectUserTicketsSchema>;
30 changes: 30 additions & 0 deletions src/generated/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ enum PronounsEnum {
theyThem
}

"""
Representation of the public data for a user's event attendance, used usually for public profiles or 'shareable ticket' pages
"""
type PublicEventAttendance {
event: Event!
id: ID!
userInfo: PublicUserInfo!
}

input PublicEventAttendanceInfo {
id: String!
}

"""
Representation of a payment log entry
"""
Expand All @@ -621,6 +634,16 @@ input PublicTicketInput {
publicTicketId: String!
}

"""
Representation of a user's publicly accessible data, to be used in public contexts like shareable ticket UIs
"""
type PublicUserInfo {
firstName: String
lastName: String
profilePicture: String
userName: String!
}

"""
Representation of the public information of a User ticket
"""
Expand Down Expand Up @@ -724,6 +747,13 @@ type Query {
"""
myTickets(input: PaginatedInputMyTicketsSearchValues!): PaginatedUserTicket!

"""
Get public event attendance info
"""
publicEventAttendanceInfo(
input: PublicEventAttendanceInfo!
): PublicEventAttendance

"""
Get a list of user tickets
"""
Expand Down
27 changes: 27 additions & 0 deletions src/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,18 @@ export enum PronounsEnum {
TheyThem = "theyThem",
}

/** Representation of the public data for a user's event attendance, used usually for public profiles or 'shareable ticket' pages */
export type PublicEventAttendance = {
__typename?: "PublicEventAttendance";
event: Event;
id: Scalars["ID"]["output"];
userInfo: PublicUserInfo;
};

export type PublicEventAttendanceInfo = {
id: Scalars["String"]["input"];
};

/** Representation of a payment log entry */
export type PublicFinanceEntryRef = {
__typename?: "PublicFinanceEntryRef";
Expand All @@ -665,6 +677,15 @@ export type PublicTicketInput = {
publicTicketId: Scalars["String"]["input"];
};

/** Representation of a user's publicly accessible data, to be used in public contexts like shareable ticket UIs */
export type PublicUserInfo = {
__typename?: "PublicUserInfo";
firstName?: Maybe<Scalars["String"]["output"]>;
lastName?: Maybe<Scalars["String"]["output"]>;
profilePicture?: Maybe<Scalars["String"]["output"]>;
userName: Scalars["String"]["output"];
};

/** Representation of the public information of a User ticket */
export type PublicUserTicket = {
__typename?: "PublicUserTicket";
Expand Down Expand Up @@ -730,6 +751,8 @@ export type Query = {
myPurchaseOrders: PaginatedPurchaseOrder;
/** Get a list of tickets for the current user */
myTickets: PaginatedUserTicket;
/** Get public event attendance info */
publicEventAttendanceInfo?: Maybe<PublicEventAttendance>;
/** Get a list of user tickets */
publicTicketInfo: PublicUserTicket;
/** Get a list of salaries associated to the user */
Expand Down Expand Up @@ -802,6 +825,10 @@ export type QueryMyTicketsArgs = {
input: PaginatedInputMyTicketsSearchValues;
};

export type QueryPublicEventAttendanceInfoArgs = {
input: PublicEventAttendanceInfo;
};

export type QueryPublicTicketInfoArgs = {
input: PublicTicketInput;
};
Expand Down
6 changes: 5 additions & 1 deletion src/schema/events/eventsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
userTicketsSchema,
ticketsSchema,
eventsToCommunitiesSchema,
UserTicketApprovalStatus,
} from "~/datasources/db/schema";
import {
PaginationOptionsType,
Expand Down Expand Up @@ -95,7 +96,10 @@ const getSearchEventsQuery = (
.where(
and(
inArray(userTicketsSchema.ticketTemplateId, subquery),
eq(userTicketsSchema.approvalStatus, "approved"),
eq(
userTicketsSchema.approvalStatus,
UserTicketApprovalStatus.Approved,
),
eq(userTicketsSchema.userId, userId),
),
),
Expand Down
Loading
Loading