Skip to content

Commit 3e0820f

Browse files
authored
Corregir la aprobación de tickets para usuarios sin equipo aceptado (#263)
Este PR corrige un error en el proceso de aprobación de tickets para usuarios que no tienen un equipo aceptado pero tienen acceso a tickets de conferencia (no tickets de hackathon). Cambios principales: 1. Se separan los tickets de usuario en dos categorías: tickets de hackathon y tickets que no son de hackathon. 2. Se aplican validaciones adicionales solo para los tickets de hackathon, incluyendo: - Verificación de contacto de emergencia - Verificación de alergias alimentarias - Verificación de estado del equipo y participación del usuario 3. Para tickets que no son de hackathon, se mantienen las validaciones básicas como RUT, país y ciudad. Este cambio permite que los usuarios sin equipo aceptado puedan obtener la aprobación de sus tickets de conferencia sin ser bloqueados por las validaciones específicas del hackathon.
1 parent ad210c0 commit 3e0820f

1 file changed

Lines changed: 71 additions & 43 deletions

File tree

src/schema/userTickets/helpers.ts

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,28 @@ export const assertCanStartTicketClaimingForEvent = async ({
110110
}
111111
};
112112

113+
type ValidateUserDataAndApproveUserTicketsOptions = {
114+
DB: ORM_TYPE;
115+
userId: string;
116+
eventId: string;
117+
logger: Logger;
118+
};
119+
120+
const HACKATHON_TICKETS_IDS_IN_PROD = [
121+
// Dia 1
122+
"8ab45972-2497-48b0-8714-f678d18bc5a9",
123+
// Dia 2
124+
"fae5b2cd-e441-4c43-845c-bfa7c59c7af1",
125+
// Inauguracion
126+
"900b2eab-3166-4e68-ab93-1831df094471",
127+
];
128+
113129
export const validateUserDataAndApproveUserTickets = async ({
114130
DB,
115131
userId,
116132
eventId,
117133
logger,
118-
}: {
119-
DB: ORM_TYPE;
120-
userId: string;
121-
eventId: string;
122-
logger: Logger;
123-
}) => {
134+
}: ValidateUserDataAndApproveUserTicketsOptions) => {
124135
const event = await eventsFetcher.searchEvents({
125136
DB,
126137
search: {
@@ -138,10 +149,15 @@ export const validateUserDataAndApproveUserTickets = async ({
138149
user: {
139150
with: {
140151
userTeams: {
152+
columns: {
153+
id: true,
154+
userParticipationStatus: true,
155+
},
141156
with: {
142157
team: {
143-
with: {
144-
event: true,
158+
columns: {
159+
id: true,
160+
teamStatus: true,
145161
},
146162
},
147163
},
@@ -155,38 +171,30 @@ export const validateUserDataAndApproveUserTickets = async ({
155171
throw applicationError("User not found", ServiceErrors.NOT_FOUND, logger);
156172
}
157173

158-
const hasTeam =
159-
userData.user?.userTeams && userData.user?.userTeams.length > 0;
160-
161-
// find the ticket for the user
162-
163-
const errors: string[] = [];
164-
165-
if (hasTeam) {
166-
const hasApprovedTeam = userData.user?.userTeams?.some((ut) => {
167-
return (
168-
ut.userParticipationStatus === UserParticipationStatusEnum.accepted
169-
);
170-
});
171-
const hasApprovedUser = userData.user?.userTeams?.some((ut) => {
172-
return ut.team.teamStatus === TeamStatusEnum.accepted;
173-
});
174-
175-
if (!hasApprovedTeam) {
176-
errors.push("User team is not approved");
177-
}
174+
const userTickets = await userTicketFetcher.searchUserTickets({
175+
DB,
176+
search: {
177+
userIds: [userId],
178+
eventIds: [eventId],
179+
approvalStatus: ["gifted"],
180+
},
181+
});
178182

179-
if (!hasApprovedUser) {
180-
errors.push("User has not confirmed participation");
181-
}
183+
const hackathonUserTickets = [];
184+
const nonHackathonUserTickets = [];
182185

183-
// If the user has a team, we check some values of userData.
186+
for (let i = 0; i < userTickets.length; i++) {
187+
const ut = userTickets[i];
184188

185-
if (!userData.emergencyPhoneNumber) {
186-
errors.push("Emergency contact is missing");
189+
if (HACKATHON_TICKETS_IDS_IN_PROD.includes(ut.ticketTemplateId)) {
190+
hackathonUserTickets.push(ut);
191+
} else {
192+
nonHackathonUserTickets.push(ut);
187193
}
188194
}
189195

196+
const errors: string[] = [];
197+
190198
if (!userData.rut) {
191199
errors.push("RUT is missing");
192200
}
@@ -199,6 +207,35 @@ export const validateUserDataAndApproveUserTickets = async ({
199207
errors.push("City is missing");
200208
}
201209

210+
if (hackathonUserTickets.length > 0) {
211+
// If the user has a team, we check some values of userData.
212+
if (!userData.emergencyPhoneNumber) {
213+
errors.push("Emergency contact is missing");
214+
}
215+
216+
if (!userData.foodAllergies) {
217+
errors.push("Emergency contact is missing");
218+
}
219+
220+
const acceptedTeams = userData.user?.userTeams?.filter((ut) => {
221+
return ut.team.teamStatus === TeamStatusEnum.accepted;
222+
});
223+
224+
if (!acceptedTeams || !acceptedTeams.length) {
225+
errors.push("User teams are not accepted");
226+
} else {
227+
const hasAcceptedParticipation = acceptedTeams.some((ut) => {
228+
return (
229+
ut.userParticipationStatus === UserParticipationStatusEnum.accepted
230+
);
231+
});
232+
233+
if (!hasAcceptedParticipation) {
234+
errors.push("User has not accepted participation");
235+
}
236+
}
237+
}
238+
202239
if (errors.length > 0) {
203240
throw applicationError(
204241
`Missing required conditions: ${errors.join(", ")}`,
@@ -207,15 +244,6 @@ export const validateUserDataAndApproveUserTickets = async ({
207244
);
208245
}
209246

210-
const userTickets = await userTicketFetcher.searchUserTickets({
211-
DB,
212-
search: {
213-
userIds: [userId],
214-
eventIds: [eventId],
215-
approvalStatus: ["gifted"],
216-
},
217-
});
218-
219247
const approvedUserTickets = await bulkApproveUserTickets({
220248
DB,
221249
userTicketIds: userTickets.map((ut) => ut.id),

0 commit comments

Comments
 (0)