Skip to content
Open
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
4 changes: 2 additions & 2 deletions backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import challengeRoutes from './src/routes/challenge.routes';
import defaultRoute from './src/routes/default.routes';
import discordRoutes from './src/routes/discord.routes';
import emailRoutes from './src/routes/email.routes';
import eventRoutes from './src/routes/event.routes';
import settingsRoutes from './src/routes/settings.routes';
import factionRoutes from './src/routes/faction.routes';
import imexportRouter from './src/routes/im_export.routes';
import newsRoutes from './src/routes/news.routes';
Expand Down Expand Up @@ -59,7 +59,7 @@ async function startServer() {
app.use('/api/role', authenticateUser, roleRoutes);
app.use('/api/user', authenticateUser, userRoutes);
app.use('/api/team', authenticateUser, teamRoutes);
app.use('/api/event', authenticateUser, eventRoutes);
app.use('/api/settings', authenticateUser, settingsRoutes);
app.use('/api/faction', authenticateUser, factionRoutes);
app.use('/api/imexport', authenticateUser, imexportRouter);
app.use('/api/permanence', authenticateUser, permanenceRoutes);
Expand Down
199 changes: 0 additions & 199 deletions backend/src/controllers/event.controller.ts

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/controllers/im_export.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import * as event_service from '../services/event.service';
import * as settings_service from '../services/settings.service';
import * as export_service from '../services/im_export.service';
import * as permanence_service from '../services/permanence.service';
import * as team_service from '../services/team.service';
Expand All @@ -22,7 +22,7 @@ export const exportAllDataToSheets: AppRequestHandler = async (_req, res) => {
const userList = await user_service.getUsersAll();
const teamList = await team_service.getTeamsAll();
const permanenceList = await permanence_service.getAllPermanencesWithUsers();
const shotgunList = await event_service.getAllTeamShotguns();
const shotgunList = await settings_service.getAllTeamShotguns();

// 2. Mapping -> format pour Google Sheets (array de array)
const usersValues = [
Expand Down
139 changes: 139 additions & 0 deletions backend/src/controllers/settings.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import * as settings_service from '../services/settings.service';
import * as team_service from '../services/team.service';
import { Conflict, Error, Ok, Teapot, Unauthorized } from '../shared/http/responses';
import { shotgun_password } from '../shared/secrets/secrets';
import type { AppRequestHandler } from '../types/http';
import type { ShotgunBody, ToggleStatusBody } from '../dto/event.dto';

export const getSettingStatus: AppRequestHandler = async (req, res) => {
const { setting } = req.params;

if (!setting || !settings_service.isSetting(setting)) {
Error(res, { msg: 'Setting événement inconnu.' });
return;
}

try {
const status = await settings_service.getSettingStatus(setting);
if (setting === 'shotgun') {
Ok(res, { data: { status, password: status ? shotgun_password : '' } });
} else {
Ok(res, { data: status });
}
} catch (error) {
Error(res, { msg: 'Erreur lors de la récupération du statut :' + error });
}
};

export const getAvailableSettings: AppRequestHandler = async (req, res) => {
try {
const userPermission = req.user?.userPermission ?? '';
const userRoles = req.user?.userRoles?.map((role) => role.roleName) ?? [];
const settings = await settings_service.getAvailableSettings(userPermission, userRoles);
Ok(res, { data: settings });
} catch (error) {
Error(res, { msg: 'Erreur lors de la récupération des settings :' + error });
}
};

export const getAdminSettings: AppRequestHandler = async (_req, res) => {
try {
const settings = await settings_service.getAllSettings();
Ok(res, { data: settings });
} catch (error) {
Error(res, { msg: 'Erreur lors de la récupération des settings :' + error });
}
};

export const getShotgunAttempts: AppRequestHandler = async (_req, res) => {
try {
const shotgunAttempts = await settings_service.getAllTeamShotguns();
const shotgunAttemptsWithLeaders = await Promise.all(
shotgunAttempts.map(async (attempt) => {
if (!attempt.teamId) {
return { ...attempt, leaderCount: 0 };
}

const teamUsers = await team_service.getTeamUsers(attempt.teamId);
const leaderCount = teamUsers.filter((user) => user.permission !== 'Nouveau').length;

return { ...attempt, leaderCount };
}),
);

Ok(res, { data: shotgunAttemptsWithLeaders });
} catch (error) {
Error(res, { msg: 'Erreur lors de la récupération des tentatives shotgun : ' + error });
}
};

export const shotgunAttempt: AppRequestHandler<ShotgunBody> = async (req, res) => {
const { password } = req.body;

const userId = req.user?.userId;

if (!userId) {
Unauthorized(res, { msg: 'Utilisateur non authentifié.' });
return;
}

if (!shotgun_password) {
Error(res, { msg: 'Mot de passe shotgun non configuré côté serveur.' });
return;
}

if (password !== shotgun_password) {
Teapot(res, { msg: 'Le mot de passe shotgun est incorrect.' });
return;
}

const status = await settings_service.getSettingsStatus();
if (!status?.shotgun_open) {
Unauthorized(res, { msg: 'Le shotgun est fermé.' });
return;
}
try {
const userTeam = await team_service.getUserTeam(userId);

if (!userTeam) {
Error(res, { msg: "Erreur : Tu n'as pas d'équipe !" });
return;
}

const alreadyShotgun = await settings_service.alreadyShotgun(userTeam);

if (alreadyShotgun) {
Conflict(res, { msg: 'Votre équipe est déjà dans le shotgun.' });
return;
}

await settings_service.validateShotgun(userTeam);
Ok(res, { msg: 'Shotgun validé !' });
return;
} catch (error) {
Error(res, { msg: 'Erreur pendant le shotguns : ' + error });
return;
}
};

export const updateSettingStatus: AppRequestHandler<ToggleStatusBody> = async (req, res) => {
const { setting } = req.params;
const { open } = req.body;

if (!setting || !settings_service.isSetting(setting)) {
Error(res, { msg: 'Setting événement inconnu.' });
return;
}

if (typeof open !== 'boolean') {
Error(res, { msg: "Le champ 'open' doit être un booléen." });
return;
}

try {
const result = await settings_service.updateSettingStatus(setting, open);
Ok(res, { msg: 'Paramètres mis à jour.', data: result });
} catch (error) {
Error(res, { msg: 'Erreur lors de la mise à jour : ' + error });
}
};
4 changes: 2 additions & 2 deletions backend/src/controllers/team.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Event } from '../schemas/Basic/event.schema';
import * as event_service from '../services/event.service';
import * as settings_service from '../services/settings.service';
import * as faction_service from '../services/faction.service';
import * as team_service from '../services/team.service';
import { Error, Ok } from '../shared/http/responses';
Expand All @@ -14,7 +14,7 @@ export const createNewTeam: AppRequestHandler<CreateTeamBody> = async (req, res)
Error(res, { msg: "Il n'y a pas de nom d'équipe" });
return;
}
const status: Event = await event_service.getEventsStatus();
const status: Event = await settings_service.getSettingsStatus();
if (!status?.pre_registration_open) {
Error(res, { msg: "L'enregistrement d'équipe est fermé." });
return;
Expand Down
Loading