diff --git a/assets/email/template.html b/assets/email/template.html index 72064c80..38dad72b 100644 --- a/assets/email/template.html +++ b/assets/email/template.html @@ -37,7 +37,7 @@ Logo UTT Arena { try { const team = await fetchTeam(request.params.teamId); + const { user } = getRequestInfo(response); // Check if the team exists if (!team) return notFound(response, ResponseError.TeamNotFound); // Check if the team is not locked - if (team.lockedAt) return forbidden(response, ResponseError.TeamLocked); - - const { user } = getRequestInfo(response); + if (team.lockedAt && request.body.userType !== UserType.coach) + return forbidden(response, ResponseError.TeamLocked); // Check if the user is already asking for a team if (user.askingTeamId) return forbidden(response, ResponseError.AlreadyAskedATeam); diff --git a/src/scripts/mails/index.ts b/src/scripts/mails/index.ts index c18a058c..36cc0dfd 100644 --- a/src/scripts/mails/index.ts +++ b/src/scripts/mails/index.ts @@ -6,7 +6,8 @@ import { Mail } from '../../services/email/types'; import { EmailAttachement } from '../../types'; import logger from '../../utils/logger'; // import { ticketsGoal } from './tickets'; -import { notPaidGoal } from './notpaid'; +// import { notPaidGoal } from './notpaid'; +import { notPaidSSBUGoal } from './notpaidssbu'; // import { discordGoal } from './discord'; // import { minorGoal } from './minor'; // import { unlockedPlayersGoal } from './unlocked'; @@ -22,7 +23,8 @@ const goals: Array = [ // discordGoal, minorGoal, // ticketsGoal, // unlockedPlayersGoal - notPaidGoal, + // notPaidGoal, + notPaidSSBUGoal, ]; (async () => { diff --git a/src/scripts/mails/notpaidssbu.ts b/src/scripts/mails/notpaidssbu.ts new file mode 100644 index 00000000..60a569c2 --- /dev/null +++ b/src/scripts/mails/notpaidssbu.ts @@ -0,0 +1,72 @@ +import { MailGoal } from '.'; +import database from '../../services/database'; +import { EmailAttachement } from '../../types'; + +export const notPaidSSBUGoal: MailGoal = { + collector: () => + database.user.findMany({ + distinct: ['id'], + where: { + AND: [ + { + OR: [ + { + cartItems: { + some: { + AND: [ + { + itemId: { + startsWith: 'ticket-', + }, + forcePaid: false, + }, + { + cart: { + transactionState: { + not: 'paid', + }, + }, + }, + ], + }, + }, + }, + { + cartItems: { + none: {}, + }, + }, + ], + }, + { + team: { + tournament: { + id: 'ssbu', + }, + }, + }, + { + team: { + lockedAt: null, + }, + }, + ], + }, + }), + sections: [ + { + title: "Ton inscription n'a pas été confirmée", + components: [ + "L'UTT Arena approche à grand pas, et ton inscription pour le tournoi SSBU n'est pas encore confirmée. Pour verrouiller ta place, il ne te reste plus qu'à la payer en accédant à la boutique sur le site.", + "\nN'oublie pas que tu peux décider de ramener ta propre Nintendo Switch avec SSBU (all DLCs) pour bénéficier d'une *réduction de 3€* sur ta place ! Cela permet également au tournoi de s'enchaîner de façon plus fluide.", + "\nOn se retrouve le 1, 2, 3 décembre dans l'Arène !", + { + location: 'https://arena.utt.fr/dashboard/team', + name: 'Accéder à arena.utt.fr', + }, + ], + }, + ], + // eslint-disable-next-line require-await + attachments: async () => [] as EmailAttachement[], +};