Skip to content

Commit

Permalink
Merge pull request #195 from ungdev/dev
Browse files Browse the repository at this point in the history
Add compression and badge ability
  • Loading branch information
DevNono authored Nov 20, 2023
2 parents b13d00e + 668888a commit f9f44fe
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 16 deletions.
2 changes: 1 addition & 1 deletion assets/email/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<tr style="background-color: {{& style.text.color}}">
<td style="text-align: right">
<img
src="https://arena.utt.fr/images/logo.png"
src="https://arena.utt.fr/images/logo.webp"
alt="Logo UTT Arena"
title="Logo UTT Arena"
width="140"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@ung/node-etupay": "^3.0.0",
"axios": "^1.5.1",
"bcryptjs": "^2.4.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
Expand Down Expand Up @@ -46,6 +47,7 @@
"@types/bcryptjs": "^2.4.4",
"@types/chai": "^4.3.8",
"@types/chai-string": "^1.4.3",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.14",
"@types/express": "^4.17.19",
"@types/jsonwebtoken": "^9.0.3",
Expand Down
39 changes: 39 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express, { Request, Response } from 'express';
import * as Sentry from '@sentry/node';
import cors from 'cors';
import helmet from 'helmet';
import compression from 'compression';

import { notFound } from './utils/responses';
import { Error } from './types';
Expand All @@ -23,8 +24,12 @@ if (!env.test) app.use(rateLimiter);
Sentry.init({ dsn: env.log.sentryDsn, environment: env.environment });
app.use(Sentry.Handlers.requestHandler({}));

// Enable morgan logger
app.use(morgan());

// Enable compression
app.use(compression());

// Security middlewares
app.use(cors(), helmet());

Expand Down
5 changes: 2 additions & 3 deletions src/controllers/teams/createTeamRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ export default [
async (request: Request, response: Response, next: NextFunction) => {
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 && user.type !== 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);
Expand Down
6 changes: 4 additions & 2 deletions src/scripts/mails/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,7 +23,8 @@ const goals: Array<MailGoal> = [
// discordGoal, minorGoal,
// ticketsGoal,
// unlockedPlayersGoal
notPaidGoal,
// notPaidGoal,
notPaidSSBUGoal,
];

(async () => {
Expand Down
72 changes: 72 additions & 0 deletions src/scripts/mails/notpaidssbu.ts
Original file line number Diff line number Diff line change
@@ -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[],
};
20 changes: 10 additions & 10 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ const env = {
teamRoleColor: Number.parseInt(loadEnv('DISCORD_TEAM_ROLE_COLOR')) || 0x3498db,
oauthCallback: `${apiEndpoint}${apiEndpointPrefix === '/' ? '' : '/'}discord/oauth`,
webhooks: {
channel_lol: process.env.DISCORD_WEBHOOK_TOURNAMENT_LOL,
channel_ssbu: process.env.DISCORD_WEBHOOK_TOURNAMENT_SSBU,
channel_cs2: process.env.DISCORD_WEBHOOK_TOURNAMENT_CS2,
channel_pokemon: process.env.DISCORD_WEBHOOK_TOURNAMENT_POKEMON,
channel_rl: process.env.DISCORD_WEBHOOK_TOURNAMENT_RL,
channel_osu: process.env.DISCORD_WEBHOOK_TOURNAMENT_OSU,
channel_tft: process.env.DISCORD_WEBHOOK_TOURNAMENT_TFT,
channel_open: process.env.DISCORD_WEBHOOK_TOURNAMENT_OPEN,
channel_other: process.env.DISCORD_WEBHOOK_TOURNAMENT_OTHER,
contact: process.env.DISCORD_WEBHOOK_CONTACT,
channel_lol: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_LOL') || '',
channel_ssbu: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_SSBU') || '',
channel_cs2: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_CS2') || '',
channel_pokemon: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_POKEMON') || '',
channel_rl: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_RL') || '',
channel_osu: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_OSU') || '',
channel_tft: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_TFT') || '',
channel_open: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_OPEN') || '',
channel_other: loadEnv('DISCORD_WEBHOOK_TOURNAMENT_OTHER') || '',
contact: loadEnv('DISCORD_WEBHOOK_CONTACT') || '',
},
},
log: {
Expand Down

0 comments on commit f9f44fe

Please sign in to comment.