Skip to content
Merged
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
8 changes: 4 additions & 4 deletions backend/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bcrypt from 'bcryptjs';
import bigInt from 'big-integer';
import { sign, verify } from 'jsonwebtoken';
import type { EmailOptions } from '../../types/email';
import type { EmailOptions } from '../types/email';
import { templateResetPassword } from '../email/email.registry';
import { compileTemplate } from '../email/email.renderer';
import * as auth_service from '../services/auth.service';
Expand All @@ -10,9 +10,9 @@
import * as registration_service from '../services/registration.service';
import * as role_service from '../services/role.service';
import * as user_service from '../services/user.service';
import { Error, Ok, Unauthorized } from '../utils/responses';
import { email_from, jwtSecret, service_url } from '../utils/secret';
import { decodeToken } from '../utils/token';
import { Error, Ok, Unauthorized } from '../shared/http/responses';
import { email_from, jwtSecret, service_url } from '../shared/secrets/secrets';
import { decodeToken } from '../shared/utils/token';
import type { AppRequestHandler } from '../types/http';
import type {
LoginBody,
Expand Down Expand Up @@ -213,7 +213,7 @@

try {
// Vérifiez et décodez le token
const decoded: any = verify(token, jwtSecret);

Check warning on line 216 in backend/src/controllers/auth.controller.ts

View workflow job for this annotation

GitHub Actions / lint-api

Unexpected any. Specify a different type

// Trouvez l'utilisateur par ID
const user = await user_service.getUserById(decoded.userId);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/banned.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as banned_service from '../services/banned.service';
import { Error, Ok } from '../utils/responses';
import { Error, Ok } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type { BannedBody, BannedIdParams } from '../dto/banned.dto';

Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/bus.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as bus_service from '../services/bus.service';
import { generateEmailHtml, sendEmail } from '../services/email.service';
import { Error, Ok } from '../utils/responses';
import { email_from } from '../utils/secret';
import { Error, Ok } from '../shared/http/responses';
import { email_from } from '../shared/secrets/secrets';
import type { AppRequestHandler } from '../types/http';

export const sendBusAttributionEmails: AppRequestHandler = async (_req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/challenge.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as challenge_service from '../services/challenge.service';
import { Created, Error, Ok, Unauthorized } from '../utils/responses';
import { Created, Error, Ok, Unauthorized } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type {
CreateChallengeBody,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/discord.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as discord_service from '../services/discord.service';
import { Error, Ok, ServiceUnavailable } from '../utils/responses';
import { Error, Ok, ServiceUnavailable } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type { DiscordBody } from '../dto/discord.dto';

Expand Down
8 changes: 4 additions & 4 deletions backend/src/controllers/email.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { EmailOptions } from '../../types/email';
import type { EmailOptions } from '../types/email';
import { defaultPreviewData } from '../email/email.preview-data';
import { generateEmailHtml, getRecipients, sendEmail } from '../services/email.service';
import * as registration_service from '../services/registration.service';
import * as user_service from '../services/user.service';
import { Error, Ok } from '../utils/responses';
import { email_from, service_url } from '../utils/secret';
import { getLatestUploadedDocument } from '../utils/uploadDocuments';
import { Error, Ok } from '../shared/http/responses';
import { email_from, service_url } from '../shared/secrets/secrets';
import { getLatestUploadedDocument } from '../shared/storage/uploadDocuments';
import type { AppRequestHandler } from '../types/http';
import type { EmailRequestBody } from '../dto/email.dto';

Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/event.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as event_service from '../services/event.service';
import * as team_service from '../services/team.service';
import { Conflict, Error, Ok, Teapot, Unauthorized } from '../utils/responses';
import { shotgun_password } from '../utils/secret';
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';

Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/faction.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as faction_service from '../services/faction.service';
import { Error, Ok } from '../utils/responses';
import { Error, Ok } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type { FactionQuery, FactionBody } from '../dto/faction.dto';

Expand Down
6 changes: 3 additions & 3 deletions backend/src/controllers/im_export.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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';
import * as user_service from '../services/user.service';
import { Error, Ok } from '../utils/responses';
import { spreadsheet_id } from '../utils/secret';
import { Error, Ok } from '../shared/http/responses';
import { spreadsheet_id } from '../shared/secrets/secrets';
import {
getLatestUploadedDocument,
isSafeUploadSegment,
removeUploadedDocuments,
toUploadedDocumentStatus,
} from '../utils/uploadDocuments';
} from '../shared/storage/uploadDocuments';
import type { AppRequestHandler } from '../types/http';
import type { UploadedDocumentParams } from '../dto/im_export.dto';

Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/news.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as email_service from '../services/email.service';
import { generateEmailHtml } from '../services/email.service';
import * as news_service from '../services/news.service';
import * as user_service from '../services/user.service';
import { Error, Ok } from '../utils/responses';
import { email_from } from '../utils/secret';
import { Error, Ok } from '../shared/http/responses';
import { email_from } from '../shared/secrets/secrets';
import type { AppRequestHandler } from '../types/http';
import type { NewsBody, NewsQuery } from '../dto/news.dto';

Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/permanence.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as permanence_service from '../services/permanence.service';
import { Error, Ok } from '../utils/responses';
import { Error, Ok } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type { PermanenceBody, PermQuery } from '../dto/permanence.dto';

Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/role.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as role_service from '../services/role.service';
import { Error, Ok } from '../utils/responses';
import { Error, Ok } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type {
PermissionBody,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/team.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Event } from '../schemas/Basic/event.schema';
import * as event_service from '../services/event.service';
import * as faction_service from '../services/faction.service';
import * as team_service from '../services/team.service';
import { Error, Ok } from '../utils/responses';
import { Error, Ok } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';
import type { CreateTeamBody, CreateTeamLightBody, ModifyTeamBody, TeamQuery } from '../dto/team.dto';

Expand Down
14 changes: 5 additions & 9 deletions backend/src/controllers/tent.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { generateEmailHtml, sendEmail } from '../services/email.service';
import * as tent_service from '../services/tent.service';
import { getUserById } from '../services/user.service';
import { Error, Ok } from '../utils/responses';
import { email_from } from '../utils/secret';
import { Error, Ok } from '../shared/http/responses';
import { email_from } from '../shared/secrets/secrets';
import type { AppRequestHandler } from '../types/http';
import type { CreateTentBody, ToggleTentBody } from '../dto/tent.dto';

Expand All @@ -17,7 +17,7 @@
try {
await tent_service.createTent(userId1, userId2);
Ok(res, { msg: 'Tente réservée avec succès.' });
} catch (err: any) {

Check warning on line 20 in backend/src/controllers/tent.controller.ts

View workflow job for this annotation

GitHub Actions / lint-api

Unexpected any. Specify a different type
Error(res, { msg: err.message || 'Erreur lors de la création de la tente.' });
}
};
Expand Down Expand Up @@ -89,22 +89,18 @@
const emailOptions = {
from: email_from,
to: [user1.email, user2.email],
subject: confirmed
? "🎉 Votre tente a été validée !"
: "⛺ Votre tente a été invalidée",
text: "", // optionnel
subject: confirmed ? '🎉 Votre tente a été validée !' : '⛺ Votre tente a été invalidée',
text: '', // optionnel
html: htmlEmail,
};

// Envoi
await sendEmail(emailOptions);

Ok(res, {
msg: confirmed
? "Tente validée et email envoyé."
: "Tente invalidée et email envoyé.",
msg: confirmed ? 'Tente validée et email envoyé.' : 'Tente invalidée et email envoyé.',
});
} catch (err: any) {

Check warning on line 103 in backend/src/controllers/tent.controller.ts

View workflow job for this annotation

GitHub Actions / lint-api

Unexpected any. Specify a different type
console.error(err);
Error(res, {
msg: err.message || "Erreur lors de la mise à jour ou de l'envoi d'email.",
Expand Down
10 changes: 5 additions & 5 deletions backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type {
AdminCreateUserDto,
CreateUserContactInformationDto,
CreateUserContactInformationBody,
PermissionParams,
ProfileBody,
SyncBody,
UserIdParams,
VssSubmissionPayload,
AdminCreateUserBody,
} from '../dto/user.dto';
import * as user_service from '../services/user.service';
import { Error, Ok } from '../utils/responses';
import { Error, Ok } from '../shared/http/responses';
import type { AppRequestHandler } from '../types/http';

export const getUsersAdmin: AppRequestHandler = async (_req, res) => {
Expand Down Expand Up @@ -85,7 +85,7 @@ export const getUserContactInformation: AppRequestHandler = async (req, res) =>
}
};

export const createUserContactInformation: AppRequestHandler<CreateUserContactInformationDto> = async (req, res) => {
export const createUserContactInformation: AppRequestHandler<CreateUserContactInformationBody> = async (req, res) => {
const userId = req.user?.userId;
const contact = req.body;

Expand Down Expand Up @@ -153,7 +153,7 @@ export const adminUpdateUser: AppRequestHandler<unknown, unknown, UserIdParams>
}
};

export const adminCreateUser: AppRequestHandler<AdminCreateUserDto> = async (req, res) => {
export const adminCreateUser: AppRequestHandler<AdminCreateUserBody> = async (req, res) => {
try {
const user = await user_service.adminCreateUser(req.body);

Expand Down
16 changes: 8 additions & 8 deletions backend/src/database/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { drizzle } from "drizzle-orm/node-postgres";
import { Client } from "pg";
import { postgres_db, postgres_host, postgres_password, postgres_port, postgres_user } from '../utils/secret';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';
import { postgres_db, postgres_host, postgres_password, postgres_port, postgres_user } from '../shared/secrets/secrets';

// ✅ Import de tous tes schémas ici
import * as challenge from '../schemas/Basic/challenge.schema';
Expand All @@ -11,16 +11,16 @@ import * as permanence from '../schemas/Basic/permanence.schema';
import * as role from '../schemas/Basic/role.schema';
import * as team from '../schemas/Basic/team.schema';
import * as user from '../schemas/Basic/user.schema';
import * as busattribution from "../schemas/Relational/busattribution.schema";
import * as busattribution from '../schemas/Relational/busattribution.schema';
import * as challengValidation from '../schemas/Relational/challengevalidation.schema';
import * as registration from "../schemas/Relational/registration.schema";
import * as rolepoints from "../schemas/Relational/rolepoints.schema";
import * as registration from '../schemas/Relational/registration.schema';
import * as rolepoints from '../schemas/Relational/rolepoints.schema';
import * as teamFaction from '../schemas/Relational/teamfaction.schema';
import * as teamShotgun from '../schemas/Relational/teamshotgun.schema';
import * as userPermanence from '../schemas/Relational/userpermanences.schema';
import * as userRole from '../schemas/Relational/userroles.schema';
import * as userTeam from '../schemas/Relational/userteams.schema';
import * as tent from "../schemas/Relational/usertent.schema";
import * as tent from '../schemas/Relational/usertent.schema';

const schema = {
...user,
Expand All @@ -40,7 +40,7 @@ const schema = {
...busattribution,
...registration,
...tent,
...rolepoints
...rolepoints,
};

const client = new Client({
Expand Down
14 changes: 7 additions & 7 deletions backend/src/database/initdb/initUser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { userSchema } from "../../schemas/Basic/user.schema";
import { hashPassword } from "../../services/auth.service";
import { email_password } from "../../utils/secret";
import { db } from "../db"; // Assurez-vous que votre instance db est correcte
import { userSchema } from '../../schemas/Basic/user.schema';
import { hashPassword } from '../../services/auth.service';
import { email_password } from '../../shared/secrets/secrets';
import { db } from '../db'; // Assurez-vous que votre instance db est correcte

export const initUser = async () => {
const existingUser = await db.select().from(userSchema).limit(1);
Expand All @@ -11,9 +11,9 @@ export const initUser = async () => {
// Si il n'y a pas de ligne existante, insérer une nouvelle ligne
if (existingUser.length === 0) {
await db.insert(userSchema).values({
first_name: "Integration UTT",
last_name: "Integration UTT",
email: "integration@utt.fr",
first_name: 'Integration UTT',
last_name: 'Integration UTT',
email: 'integration@utt.fr',
majeur: true,
password: hashedPassword,
permission: 'Admin',
Expand Down
11 changes: 1 addition & 10 deletions backend/src/dto/email.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
type EmailPayload = {
subject: string;
templateName: string;
recipientsGroups?: string[];
sendTo?: string[];
html?: string;
title?: string;
content?: string;
text?: string;
};
import { type EmailPayload } from '../types/email';

export type EmailRequestBody = {
payload?: EmailPayload;
Expand Down
36 changes: 0 additions & 36 deletions backend/src/dto/team.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,3 @@ export type TeamQuery = {
teamId?: string;
teamID?: string;
};

export type TeamMemberRow = {
userId: number;
};

export type StudentRow = {
userId: number;
email: string;
branch: string;
male?: boolean;
};

export type TeamAssignmentNotification = {
email: string;
teamId: number;
};

export type TeamRow = {
teamId: number;
name: string;
description: string;
type: string;
socialLink: string;
riCompatible: boolean;
};

export type TeamDistributionState = TeamRow & {
size: number;
girlsCount: number;
};

export type TeamSizeRow = {
teamId: number;
teamName: string;
size: number;
};
6 changes: 3 additions & 3 deletions backend/src/dto/user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type VssSubmissionAnswer } from '../services/user.service';
import { type VssSubmissionAnswer } from '../types/user';

export interface AdminCreateUserDto {
export interface AdminCreateUserBody {
firstName: string;
lastName: string;
email: string;
Expand All @@ -26,7 +26,7 @@ export type ProfileBody = {
contact: string;
};

export type CreateUserContactInformationDto = {
export type CreateUserContactInformationBody = {
emergency_contact_name: string;
emergency_contact_phone: string;
};
Expand Down
4 changes: 2 additions & 2 deletions backend/src/email/email.preview-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TemplateData } from '../../types/email';
import { service_url } from '../utils/secret';
import type { TemplateData } from '../types/email';
import { service_url } from '../shared/secrets/secrets';

export const defaultPreviewData: Record<string, TemplateData> = {
custom: {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/email/email.registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PermanenceEmailData, TemplateRenderer, TeamAssignmentEmailData } from '../../types/email';
import type { PermanenceEmailData, TemplateRenderer, TeamAssignmentEmailData } from '../types/email';

export const templateResetPassword = 'reset-password.html';
const templateNotebook = 'notebook.html';
Expand Down
14 changes: 7 additions & 7 deletions backend/src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { type NextFunction, type Request, type Response } from "express";
import { Unauthorized } from "../utils/responses"; // Assurez-vous que cette fonction est bien définie
import { decodeToken } from "../utils/token";
import { type NextFunction, type Request, type Response } from 'express';
import { Unauthorized } from '../shared/http/responses'; // Assurez-vous que cette fonction est bien définie
import { decodeToken } from '../shared/utils/token';

export const authenticateUser = (req: Request, res: Response, next: NextFunction) => {
try {
const authHeader = req.headers.authorization;

if (!authHeader || !authHeader.startsWith("Bearer ")) {
return Unauthorized(res, { msg: "Unauthorized: Missing or malformed token" });
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return Unauthorized(res, { msg: 'Unauthorized: Missing or malformed token' });
}

const token = authHeader.split(" ")[1];
const token = authHeader.split(' ')[1];
const decoded = decodeToken(token);

req.user = decoded; // Ajoute les données du token à l'objet `req`
next();
} catch {
return Unauthorized(res, { msg: "Unauthorized: Invalid or expired token" });
return Unauthorized(res, { msg: 'Unauthorized: Invalid or expired token' });
}
};
4 changes: 2 additions & 2 deletions backend/src/middlewares/automation.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type NextFunction, type Request, type Response } from 'express';
import { Unauthorized } from '../utils/responses'; // Assurez-vous que cette fonction est bien définie
import { automation_token } from '../utils/secret';
import { Unauthorized } from '../shared/http/responses'; // Assurez-vous que cette fonction est bien définie
import { automation_token } from '../shared/secrets/secrets';

export const authenticateAutomation = (req: Request, res: Response, next: NextFunction) => {
try {
Expand Down
Loading
Loading