From 8d58957945b20055fb70dfe1264428c9f870c647 Mon Sep 17 00:00:00 2001 From: Maxime Letoffet Date: Wed, 31 Jul 2024 16:54:42 +0200 Subject: [PATCH 01/15] Regex fix --- backend/src/middlewares/register.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/middlewares/register.ts b/backend/src/middlewares/register.ts index 90804a3f..0f9ce2dc 100644 --- a/backend/src/middlewares/register.ts +++ b/backend/src/middlewares/register.ts @@ -8,7 +8,7 @@ export const registerMiddleware = async (req: Request, res: Response, next: Next try { const { email, password, uuid } = req.body; - const email_regex = new RegExp('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$'); + const email_regex = new RegExp('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'); if (!email_regex.test(email)) { return Error(res, { msg: "Invalid email address" }); From d97754a9dfa2464b951603c110c2e31c4a3e10cc Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Thu, 1 Aug 2024 00:37:40 +0200 Subject: [PATCH 02/15] Remove .env in .dockerignore file. --- backend/.dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/.dockerignore b/backend/.dockerignore index 23b5b627..c1fb5fa6 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -1,2 +1 @@ -.env .node_modules \ No newline at end of file From f3b474897cdc6f83bff7b8e8513ef4f57aa66087 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Wed, 7 Aug 2024 15:46:58 +0200 Subject: [PATCH 03/15] Start to work on challenges --- backend/drizzle/meta/_journal.json | 21 +++++++ .../src/controllers/challenge.controller.ts | 6 +- backend/src/schemas/challenge.schema.ts | 63 +++++++++++++++++-- backend/src/services/auth.service.ts | 5 +- backend/src/services/challenge.service.ts | 59 +++++++++++++---- backend/src/services/faction.service.ts | 11 ++++ frontend/src/components/auth/Login.tsx | 7 ++- frontend/src/services/requests/auth.ts | 2 +- 8 files changed, 149 insertions(+), 25 deletions(-) diff --git a/backend/drizzle/meta/_journal.json b/backend/drizzle/meta/_journal.json index df9855d2..489b131f 100644 --- a/backend/drizzle/meta/_journal.json +++ b/backend/drizzle/meta/_journal.json @@ -106,6 +106,27 @@ "when": 1722348395029, "tag": "0014_curved_red_ghost", "breakpoints": true + }, + { + "idx": 15, + "version": "5", + "when": 1722506975111, + "tag": "0015_oval_scarlet_witch", + "breakpoints": true + }, + { + "idx": 16, + "version": "5", + "when": 1722507083789, + "tag": "0016_lumpy_ghost_rider", + "breakpoints": true + }, + { + "idx": 17, + "version": "5", + "when": 1722507507447, + "tag": "0017_redundant_speed_demon", + "breakpoints": true } ] } \ No newline at end of file diff --git a/backend/src/controllers/challenge.controller.ts b/backend/src/controllers/challenge.controller.ts index 809fd72a..95cd8e82 100644 --- a/backend/src/controllers/challenge.controller.ts +++ b/backend/src/controllers/challenge.controller.ts @@ -16,7 +16,7 @@ export const createChallenge = async (req: Request, res: Response, next: NextFun name ?? Error(res, { msg: "No name" }); try { - await service.createChallenge(name, desc, points); + //await service.createChallenge(name, desc, points); Created(res, {}) } catch (error) { Error(res, { error }); @@ -38,10 +38,10 @@ export const deleteChallenge = async (req: Request, res: Response, next: NextFun }; export const validateChallenge = async (req: Request, res: Response, next: NextFunction) => { - const { challengeId, factionId } = req.body; + const { challengeId, associatedId, points } = req.body; try { - await service.validateChallenge(challengeId, factionId); + await service.validateChallenge(challengeId, associatedId, points); Ok(res, { msg: "challenge validated" }); } catch (error) { Error(res, { error }); diff --git a/backend/src/schemas/challenge.schema.ts b/backend/src/schemas/challenge.schema.ts index e581dc2d..e6c7b61a 100644 --- a/backend/src/schemas/challenge.schema.ts +++ b/backend/src/schemas/challenge.schema.ts @@ -1,18 +1,73 @@ -import { pgTable, serial, text, integer } from "drizzle-orm/pg-core"; +import {pgTable, serial, text, integer, pgEnum} from "drizzle-orm/pg-core"; import { factionSchema } from "./faction.schema"; +import {newstudentSchema} from "./newstudent.schema"; +import {userSchema} from "./user.schema"; +import {teamSchema} from "./team.schema"; + +export enum ChallengeType { + Student = 'Student', + StudentOrCe = 'StudentOrCe', + Team = 'Team', // peut tout faire + Faction = 'Faction', // peut creer des équipes + Free = 'Free' //peut voir les perms +} + +const challengeTypeEnum = pgEnum('challenge_type', [ + ChallengeType.Student, + ChallengeType.StudentOrCe, + ChallengeType.Team, + ChallengeType.Faction, + ChallengeType.Free, +]); + + +export const parseChallType = (chall: string): ChallengeType | undefined => { + switch (chall) { + case 'Student': + return ChallengeType.Student; + case 'StudentOrCe': + return ChallengeType.StudentOrCe; + case 'Team': + return ChallengeType.Team; + case 'Faction': + return ChallengeType.Faction; + case 'Free': + return ChallengeType.Free; + default: + return undefined; + } +} export const challengeSchema = pgTable('challenge', { id: serial('id').primaryKey(), name: text('challenge_name').notNull().unique(), description: text('challenge_desc').notNull(), - points: integer('points').notNull(), + points: text('points').notNull(), + challType: challengeTypeEnum('chall_type').notNull() }); export type challenge = typeof challengeSchema.$inferInsert; export const factionTochallengeSchema = pgTable('factionTochallenge', { - factionId: integer('faction_id').notNull().references(() => factionSchema.id), - challengeId: integer('challenge_id').notNull().references(() => challengeSchema.id), + factionId: integer('faction_id').notNull().primaryKey().references(() => factionSchema.id), + challengeId: integer('challenge_id').notNull().primaryKey().references(() => challengeSchema.id), + attributedPoints: integer('attributed_points').notNull(), }); export type factionTochallenge = typeof factionTochallengeSchema.$inferInsert; + +export const TeamTochallengeSchema = pgTable('factionTochallenge', { + teamId: integer('team_id').notNull().primaryKey().references(() => teamSchema.id), + challengeId: integer('challenge_id').notNull().primaryKey().references(() => challengeSchema.id), + attributedPoints: integer('attributed_points').notNull(), +}); + +export type TeamTochallenge = typeof TeamTochallengeSchema.$inferInsert; + +export const StudentTochallengeSchema = pgTable('studentTochallenge', { + studentId: integer('student_id').notNull().primaryKey().references(() => userSchema.id), + challengeId: integer('challenge_id').notNull().primaryKey().references(() => challengeSchema.id), + attributedPoints: integer('attributed_points').notNull(), +}); + +export type studentTochallenge = typeof StudentTochallengeSchema.$inferInsert; diff --git a/backend/src/services/auth.service.ts b/backend/src/services/auth.service.ts index 7dc3fe3b..b1435087 100644 --- a/backend/src/services/auth.service.ts +++ b/backend/src/services/auth.service.ts @@ -9,12 +9,13 @@ export const validateCASTicket = async (ticket : string) => { const response = await fetch(validateUrl); if (response.ok) { const text = await response.text(); + console.log("====================validateCASTicket") + console.log(text) + console.log("validateCASTicket====================") const isValid = text.includes("authenticationSuccess"); if (isValid) { // User is authenticated return await parseUsernameFromCASResponse(text); - - } else { console.error("CAS ticket validation failed"); } diff --git a/backend/src/services/challenge.service.ts b/backend/src/services/challenge.service.ts index 95649bf5..e9d56725 100644 --- a/backend/src/services/challenge.service.ts +++ b/backend/src/services/challenge.service.ts @@ -1,7 +1,13 @@ -import { challengeSchema, challenge, factionTochallengeSchema, factionTochallenge } from "../schemas/challenge.schema" -import { addPoints } from "./faction.service" +import { + challengeSchema, + challenge, + factionTochallengeSchema, + factionTochallenge, + ChallengeType +} from "../schemas/challenge.schema" +import {addPoints, removePoints} from "./faction.service" import { db } from "../database/db" -import { eq } from 'drizzle-orm' +import {and, eq} from 'drizzle-orm' export const getAllChallenges = async () => { try { @@ -20,8 +26,17 @@ export const getChallenge = async (id: number) => { } } -export const createChallenge = async (name: string, description: string, points: number) => { - const newChallenge: challenge = { name, description, points}; +export const getFactionChallenges = async (factionId: number) => { + try { + const challs = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema.factionId, factionId)) + return challs; + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + +export const createChallenge = async (name: string, description: string, points: string, challType: ChallengeType) => { + const newChallenge: challenge = {name: name, description: description, points: points, challType: challType}; try { await db.insert(challengeSchema).values(newChallenge); } catch (error) { @@ -38,14 +53,34 @@ export const deleteChallenge = async (id: number) => { } } -export const validateChallenge = async (challengeId: number, factionId: number) => { +export const validateChallenge = async (challengeId: number, associatedId: number, attributedPoints: number) => { + //First get the type of challenge + const challenge = await db.select().from(challengeSchema).where(eq(challengeSchema.id, challengeId)); + if(!challenge || challenge.length === 0) throw new Error("No challenge with id '" + challengeId + "'") + const challType = challenge[0].challType + const newFacToChall: factionTochallenge = { challengeId, factionId: associatedId, attributedPoints}; + const alreadyValidate = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema, newFacToChall)); + //if(alreadyValidate.length > 0) throw new Error(`Challenge ${challengeId} already validated for team ${factionId}.`) + if (alreadyValidate.length === 0) { + await addPoints(associatedId, attributedPoints); + await db.insert(factionTochallengeSchema).values(newFacToChall); + } +} + +export const unvalidateChallenge = async (challengeId: number, factionId: number) => { try { - const newFacToChall: factionTochallenge = { challengeId, factionId}; - const alreadyValidate = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema, newFacToChall)); - if (alreadyValidate.length === 0) { - const points = (await getChallenge(challengeId)).points; - addPoints(factionId, points); - await db.insert(factionTochallengeSchema).values(newFacToChall); + const newFacToChall = { challengeId, factionId}; + const alreadyValidate = await db.select() + .from(factionTochallengeSchema) + .where( + and( + eq(factionTochallengeSchema.challengeId, challengeId), + eq(factionTochallengeSchema.factionId, factionId) + ) + ); + if (alreadyValidate.length > 0) { + await removePoints(factionId, alreadyValidate[0].attributedPoints); + await db.delete(factionTochallengeSchema).where(eq(factionTochallengeSchema, alreadyValidate[0])) } } catch (error) { throw new Error("Failed to create challenge to faction. Please try again later."); diff --git a/backend/src/services/faction.service.ts b/backend/src/services/faction.service.ts index 12028118..b8e9fa0d 100644 --- a/backend/src/services/faction.service.ts +++ b/backend/src/services/faction.service.ts @@ -62,3 +62,14 @@ export const addPoints = async (id: number, points: number) => { throw new Error("Failed to add points. Please try again later."); } } + +export const removePoints = async (id: number, points: number) => { + const current_points = await getPoints(id); + try { + await db.update(factionSchema) + .set({ points: current_points - points }) + .where(eq(factionSchema.id, id)); + } catch (error) { + throw new Error("Failed to remove points. Please try again later."); + } +} \ No newline at end of file diff --git a/frontend/src/components/auth/Login.tsx b/frontend/src/components/auth/Login.tsx index 10477426..837a22ec 100644 --- a/frontend/src/components/auth/Login.tsx +++ b/frontend/src/components/auth/Login.tsx @@ -90,16 +90,18 @@ const LoginForm = () => { }; const TryLogin = async () => { - localStorage.setItem("tryLogin", "false"); try { //CAS CONNEXTION const urlParams = new URLSearchParams(window.location.search); const ticket = urlParams.get("ticket"); - + console.log("coucou") if(ticket){ const {token} = await handleCASTicket(ticket); + console.log(token) + localStorage.setItem("tryLogin", "false"); localStorage.setItem("authToken", token); + console.log("redirect /Home") window.location.href = "/Home"; } @@ -140,7 +142,6 @@ const LoginForm = () => { } - const getContainerClass = () => { if (stateNewLogin) return "active login"; if (stateNewRegister) return "active register"; diff --git a/frontend/src/services/requests/auth.ts b/frontend/src/services/requests/auth.ts index f2ebcccf..136cedc6 100644 --- a/frontend/src/services/requests/auth.ts +++ b/frontend/src/services/requests/auth.ts @@ -6,7 +6,7 @@ export const isTokenValid = async (token: string) => { } export const handleCASTicket = async (ticket: string)=>{ - const response = await api.get('auth/handlecasticket/', { + const response = await api.get('auth/handlecasticket/', { params:{ "ticket" :ticket } From f3a20cebc0529a1cd1e8ea8167aeaf369d8a7c18 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Mon, 12 Aug 2024 10:20:54 +0200 Subject: [PATCH 04/15] update --- backend/src/services/challenge.service.ts | 42 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/src/services/challenge.service.ts b/backend/src/services/challenge.service.ts index e9d56725..516e4115 100644 --- a/backend/src/services/challenge.service.ts +++ b/backend/src/services/challenge.service.ts @@ -3,11 +3,12 @@ import { challenge, factionTochallengeSchema, factionTochallenge, - ChallengeType + ChallengeType, StudentTochallengeSchema } from "../schemas/challenge.schema" import {addPoints, removePoints} from "./faction.service" import { db } from "../database/db" import {and, eq} from 'drizzle-orm' +import {userSchema} from "../schemas/user.schema"; export const getAllChallenges = async () => { try { @@ -57,11 +58,46 @@ export const validateChallenge = async (challengeId: number, associatedId: numbe //First get the type of challenge const challenge = await db.select().from(challengeSchema).where(eq(challengeSchema.id, challengeId)); if(!challenge || challenge.length === 0) throw new Error("No challenge with id '" + challengeId + "'") - const challType = challenge[0].challType + const challType: ChallengeType = challenge[0].challType + switch (challType) { + case ChallengeType.Student: + //means associatedId is a student + //checking user exist + const user = await db.select().from(userSchema).where(eq(userSchema.id, associatedId)); + if(!user || user.length === 0) throw new Error("No user with id '" + associatedId + "'") + //check user is not CE + if(user[0].permission === ) + //Associating the challenge to the user + //checking is event already associated with this user + const associatedChall = await db.select().from(StudentTochallengeSchema) + .where( + and( + eq(StudentTochallengeSchema.challengeId, challengeId), + eq(StudentTochallengeSchema.studentId, associatedId) + ) + ); + + if(associatedChall) throw new Error("Event already associated with this user. userId '" + associatedId + "'") + //associating the event + await db.insert(StudentTochallengeSchema).values({ + challengeId: challengeId, + studentId: associatedId, + attributedPoints: attributedPoints + }).execute(); + break; + case ChallengeType.StudentOrCe: + break; + case ChallengeType.Team: + break; + case ChallengeType.Faction: + break; + case ChallengeType.Free: + break; + } const newFacToChall: factionTochallenge = { challengeId, factionId: associatedId, attributedPoints}; const alreadyValidate = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema, newFacToChall)); //if(alreadyValidate.length > 0) throw new Error(`Challenge ${challengeId} already validated for team ${factionId}.`) - if (alreadyValidate.length === 0) { + if (!alreadyValidate || alreadyValidate.length === 0) { await addPoints(associatedId, attributedPoints); await db.insert(factionTochallengeSchema).values(newFacToChall); } From 49471689a082ec427e8b071fd8da743c91539a33 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Fri, 16 Aug 2024 23:04:24 +0200 Subject: [PATCH 05/15] choses obscures avec la db --- backend/drizzle/0000_luxuriant_mandrill.sql | 103 --- backend/drizzle/0001_bright_strong_guy.sql | 1 - .../drizzle/0002_large_mulholland_black.sql | 1 - backend/drizzle/0003_odd_beyonder.sql | 1 - backend/drizzle/0004_fluffy_kate_bishop.sql | 1 - backend/drizzle/0005_quick_doorman.sql | 1 - backend/drizzle/0006_huge_pride.sql | 8 - backend/drizzle/0007_brief_joseph.sql | 11 - .../drizzle/0008_cheerful_titanium_man.sql | 2 - backend/drizzle/0009_awesome_vermin.sql | 9 - backend/drizzle/0010_sad_redwing.sql | 1 - .../drizzle/0011_ambitious_albert_cleary.sql | 32 - backend/drizzle/0011_jittery_nekra.sql | 10 - .../drizzle/0012_chilly_squadron_sinister.sql | 20 - backend/drizzle/0013_acoustic_gabe_jones.sql | 21 - backend/drizzle/0014_curved_red_ghost.sql | 5 - backend/drizzle/meta/0000_snapshot.json | 429 ------------ backend/drizzle/meta/0001_snapshot.json | 429 ------------ backend/drizzle/meta/0002_snapshot.json | 429 ------------ backend/drizzle/meta/0003_snapshot.json | 429 ------------ backend/drizzle/meta/0004_snapshot.json | 429 ------------ backend/drizzle/meta/0005_snapshot.json | 429 ------------ backend/drizzle/meta/0006_snapshot.json | 435 ------------ backend/drizzle/meta/0007_snapshot.json | 478 ------------- backend/drizzle/meta/0008_snapshot.json | 479 ------------- backend/drizzle/meta/0009_snapshot.json | 479 ------------- backend/drizzle/meta/0010_snapshot.json | 485 ------------- backend/drizzle/meta/0011_snapshot.json | 662 ------------------ backend/drizzle/meta/0012_snapshot.json | 539 -------------- backend/drizzle/meta/0013_snapshot.json | 594 ---------------- backend/drizzle/meta/0014_snapshot.json | 588 ---------------- backend/drizzle/meta/_journal.json | 120 +--- 32 files changed, 4 insertions(+), 7656 deletions(-) delete mode 100644 backend/drizzle/0000_luxuriant_mandrill.sql delete mode 100644 backend/drizzle/0001_bright_strong_guy.sql delete mode 100644 backend/drizzle/0002_large_mulholland_black.sql delete mode 100644 backend/drizzle/0003_odd_beyonder.sql delete mode 100644 backend/drizzle/0004_fluffy_kate_bishop.sql delete mode 100644 backend/drizzle/0005_quick_doorman.sql delete mode 100644 backend/drizzle/0006_huge_pride.sql delete mode 100644 backend/drizzle/0007_brief_joseph.sql delete mode 100644 backend/drizzle/0008_cheerful_titanium_man.sql delete mode 100644 backend/drizzle/0009_awesome_vermin.sql delete mode 100644 backend/drizzle/0010_sad_redwing.sql delete mode 100644 backend/drizzle/0011_ambitious_albert_cleary.sql delete mode 100644 backend/drizzle/0011_jittery_nekra.sql delete mode 100644 backend/drizzle/0012_chilly_squadron_sinister.sql delete mode 100644 backend/drizzle/0013_acoustic_gabe_jones.sql delete mode 100644 backend/drizzle/0014_curved_red_ghost.sql delete mode 100644 backend/drizzle/meta/0000_snapshot.json delete mode 100644 backend/drizzle/meta/0001_snapshot.json delete mode 100644 backend/drizzle/meta/0002_snapshot.json delete mode 100644 backend/drizzle/meta/0003_snapshot.json delete mode 100644 backend/drizzle/meta/0004_snapshot.json delete mode 100644 backend/drizzle/meta/0005_snapshot.json delete mode 100644 backend/drizzle/meta/0006_snapshot.json delete mode 100644 backend/drizzle/meta/0007_snapshot.json delete mode 100644 backend/drizzle/meta/0008_snapshot.json delete mode 100644 backend/drizzle/meta/0009_snapshot.json delete mode 100644 backend/drizzle/meta/0010_snapshot.json delete mode 100644 backend/drizzle/meta/0011_snapshot.json delete mode 100644 backend/drizzle/meta/0012_snapshot.json delete mode 100644 backend/drizzle/meta/0013_snapshot.json delete mode 100644 backend/drizzle/meta/0014_snapshot.json diff --git a/backend/drizzle/0000_luxuriant_mandrill.sql b/backend/drizzle/0000_luxuriant_mandrill.sql deleted file mode 100644 index 5331c1ea..00000000 --- a/backend/drizzle/0000_luxuriant_mandrill.sql +++ /dev/null @@ -1,103 +0,0 @@ -DO $$ BEGIN - CREATE TYPE "permission" AS ENUM('newStudent', 'Student', 'Admin', 'RespoCE', 'Respo', 'Anim'); -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "challenge" ( - "id" serial PRIMARY KEY NOT NULL, - "challenge_name" text NOT NULL, - "challenge_desc" text NOT NULL, - "points" integer NOT NULL, - CONSTRAINT "challenge_challenge_name_unique" UNIQUE("challenge_name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "factionTochallenge" ( - "faction_id" integer NOT NULL, - "challenge_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "event" ( - "id" serial PRIMARY KEY NOT NULL, - "event_name" text NOT NULL, - "state" boolean NOT NULL, - CONSTRAINT "event_event_name_unique" UNIQUE("event_name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "faction" ( - "id" serial PRIMARY KEY NOT NULL, - "team_name" text NOT NULL, - "points" integer NOT NULL, - CONSTRAINT "faction_team_name_unique" UNIQUE("team_name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "role" ( - "id" serial PRIMARY KEY NOT NULL, - "role_name" text NOT NULL, - "role_desc" text NOT NULL, - CONSTRAINT "role_role_name_unique" UNIQUE("role_name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "userToRole" ( - "user_id" integer NOT NULL, - "role_id" integer NOT NULL, - "isWish" boolean NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "team" ( - "id" serial PRIMARY KEY NOT NULL, - "isOfficial" boolean NOT NULL, - "timeCode" bigint, - "team_name" text NOT NULL, - "city_id" integer, - CONSTRAINT "team_team_name_unique" UNIQUE("team_name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user" ( - "id" serial PRIMARY KEY NOT NULL, - "first_name" text NOT NULL, - "last_name" text NOT NULL, - "email" text NOT NULL, - "contact" text, - "connection_num" integer NOT NULL, - "permission" "permission" NOT NULL, - "password" text NOT NULL, - "team" integer, - CONSTRAINT "user_email_unique" UNIQUE("email") -); ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "factionTochallenge" ADD CONSTRAINT "factionTochallenge_faction_id_faction_id_fk" FOREIGN KEY ("faction_id") REFERENCES "faction"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "factionTochallenge" ADD CONSTRAINT "factionTochallenge_challenge_id_challenge_id_fk" FOREIGN KEY ("challenge_id") REFERENCES "challenge"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToRole" ADD CONSTRAINT "userToRole_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToRole" ADD CONSTRAINT "userToRole_role_id_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "team" ADD CONSTRAINT "team_city_id_faction_id_fk" FOREIGN KEY ("city_id") REFERENCES "faction"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user" ADD CONSTRAINT "user_team_team_id_fk" FOREIGN KEY ("team") REFERENCES "team"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/backend/drizzle/0001_bright_strong_guy.sql b/backend/drizzle/0001_bright_strong_guy.sql deleted file mode 100644 index b5423c01..00000000 --- a/backend/drizzle/0001_bright_strong_guy.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "team" ALTER COLUMN "timeCode" SET DATA TYPE bigint; \ No newline at end of file diff --git a/backend/drizzle/0002_large_mulholland_black.sql b/backend/drizzle/0002_large_mulholland_black.sql deleted file mode 100644 index 27764f3d..00000000 --- a/backend/drizzle/0002_large_mulholland_black.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "team" ALTER COLUMN "timeCode" SET DATA TYPE bigint; diff --git a/backend/drizzle/0003_odd_beyonder.sql b/backend/drizzle/0003_odd_beyonder.sql deleted file mode 100644 index 27764f3d..00000000 --- a/backend/drizzle/0003_odd_beyonder.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "team" ALTER COLUMN "timeCode" SET DATA TYPE bigint; diff --git a/backend/drizzle/0004_fluffy_kate_bishop.sql b/backend/drizzle/0004_fluffy_kate_bishop.sql deleted file mode 100644 index 27764f3d..00000000 --- a/backend/drizzle/0004_fluffy_kate_bishop.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "team" ALTER COLUMN "timeCode" SET DATA TYPE bigint; diff --git a/backend/drizzle/0005_quick_doorman.sql b/backend/drizzle/0005_quick_doorman.sql deleted file mode 100644 index b5423c01..00000000 --- a/backend/drizzle/0005_quick_doorman.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "team" ALTER COLUMN "timeCode" SET DATA TYPE bigint; \ No newline at end of file diff --git a/backend/drizzle/0006_huge_pride.sql b/backend/drizzle/0006_huge_pride.sql deleted file mode 100644 index 74c6ca58..00000000 --- a/backend/drizzle/0006_huge_pride.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE "userToRole" DROP CONSTRAINT "userToRole_user_id_user_id_fk"; ---> statement-breakpoint -ALTER TABLE "user" ADD COLUMN "birthday" date;--> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToRole" ADD CONSTRAINT "userToRole_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/backend/drizzle/0007_brief_joseph.sql b/backend/drizzle/0007_brief_joseph.sql deleted file mode 100644 index d67f40d3..00000000 --- a/backend/drizzle/0007_brief_joseph.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE IF NOT EXISTS "newstudentUUID" ( - "uiid" uuid PRIMARY KEY NOT NULL, - "isUsed" boolean DEFAULT false NOT NULL, - "user_id" integer NOT NULL -); ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "newstudentUUID" ADD CONSTRAINT "newstudentUUID_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/backend/drizzle/0008_cheerful_titanium_man.sql b/backend/drizzle/0008_cheerful_titanium_man.sql deleted file mode 100644 index c14bd667..00000000 --- a/backend/drizzle/0008_cheerful_titanium_man.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE "newstudentUUID" ALTER COLUMN "uiid" SET DEFAULT gen_random_uuid();--> statement-breakpoint -ALTER TABLE "newstudentUUID" ALTER COLUMN "user_id" DROP NOT NULL; \ No newline at end of file diff --git a/backend/drizzle/0009_awesome_vermin.sql b/backend/drizzle/0009_awesome_vermin.sql deleted file mode 100644 index 5b59e104..00000000 --- a/backend/drizzle/0009_awesome_vermin.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE "newstudentUUID" RENAME TO "newstudent";--> statement-breakpoint -ALTER TABLE "newstudent" RENAME COLUMN "uiid" TO "uuid";--> statement-breakpoint -ALTER TABLE "newstudent" DROP CONSTRAINT "newstudentUUID_user_id_user_id_fk"; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "newstudent" ADD CONSTRAINT "newstudent_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/backend/drizzle/0010_sad_redwing.sql b/backend/drizzle/0010_sad_redwing.sql deleted file mode 100644 index cf5bb743..00000000 --- a/backend/drizzle/0010_sad_redwing.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "user" ADD COLUMN "branch" text; \ No newline at end of file diff --git a/backend/drizzle/0011_ambitious_albert_cleary.sql b/backend/drizzle/0011_ambitious_albert_cleary.sql deleted file mode 100644 index 39abad0f..00000000 --- a/backend/drizzle/0011_ambitious_albert_cleary.sql +++ /dev/null @@ -1,32 +0,0 @@ -CREATE TABLE IF NOT EXISTS "permanence" ( - "id" serial PRIMARY KEY NOT NULL, - "name" text NOT NULL, - "desc" text NOT NULL, - "startingTime" bigint, - "duartion" bigint, - "studenNumber" integer, - CONSTRAINT "permanence_name_unique" UNIQUE("name"), - CONSTRAINT "permanence_desc_unique" UNIQUE("desc") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "userToPermanence" ( - "user_id" integer NOT NULL, - "perm_id" integer NOT NULL -); ---> statement-breakpoint -ALTER TABLE "faction" RENAME COLUMN "team_name" TO "faction_name";--> statement-breakpoint -ALTER TABLE "faction" DROP CONSTRAINT "faction_team_name_unique";--> statement-breakpoint -ALTER TABLE "user" ADD COLUMN "discord_id" text;--> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToPermanence" ADD CONSTRAINT "userToPermanence_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToPermanence" ADD CONSTRAINT "userToPermanence_perm_id_permanence_id_fk" FOREIGN KEY ("perm_id") REFERENCES "permanence"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -ALTER TABLE "faction" ADD CONSTRAINT "faction_faction_name_unique" UNIQUE("faction_name"); \ No newline at end of file diff --git a/backend/drizzle/0011_jittery_nekra.sql b/backend/drizzle/0011_jittery_nekra.sql deleted file mode 100644 index af4f83d7..00000000 --- a/backend/drizzle/0011_jittery_nekra.sql +++ /dev/null @@ -1,10 +0,0 @@ -ALTER TABLE "faction" DROP CONSTRAINT "faction_team_name_unique";--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "name" text NOT NULL;--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "desc" text NOT NULL;--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "startingTime" bigint;--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "duartion" bigint;--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "studenNumber" integer;--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "team_name";--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "points";--> statement-breakpoint -ALTER TABLE "faction" ADD CONSTRAINT "faction_name_unique" UNIQUE("name");--> statement-breakpoint -ALTER TABLE "faction" ADD CONSTRAINT "faction_desc_unique" UNIQUE("desc"); \ No newline at end of file diff --git a/backend/drizzle/0012_chilly_squadron_sinister.sql b/backend/drizzle/0012_chilly_squadron_sinister.sql deleted file mode 100644 index b5b17569..00000000 --- a/backend/drizzle/0012_chilly_squadron_sinister.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE TABLE IF NOT EXISTS "permanence" ( - "id" serial PRIMARY KEY NOT NULL, - "name" text NOT NULL, - "desc" text NOT NULL, - "startingTime" text NOT NULL, - "duration" bigint NOT NULL, - "studentNumber" integer NOT NULL, - CONSTRAINT "permanence_name_unique" UNIQUE("name") -); ---> statement-breakpoint -ALTER TABLE "faction" DROP CONSTRAINT "faction_name_unique";--> statement-breakpoint -ALTER TABLE "faction" DROP CONSTRAINT "faction_desc_unique";--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "team_name" text NOT NULL;--> statement-breakpoint -ALTER TABLE "faction" ADD COLUMN "points" integer NOT NULL;--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "name";--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "desc";--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "startingTime";--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "duartion";--> statement-breakpoint -ALTER TABLE "faction" DROP COLUMN IF EXISTS "studenNumber";--> statement-breakpoint -ALTER TABLE "faction" ADD CONSTRAINT "faction_team_name_unique" UNIQUE("team_name"); \ No newline at end of file diff --git a/backend/drizzle/0013_acoustic_gabe_jones.sql b/backend/drizzle/0013_acoustic_gabe_jones.sql deleted file mode 100644 index 45fe12f0..00000000 --- a/backend/drizzle/0013_acoustic_gabe_jones.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE IF NOT EXISTS "userToPermanence" ( - "user_id" integer NOT NULL, - "perm_id" integer NOT NULL -); ---> statement-breakpoint -ALTER TABLE "faction" RENAME COLUMN "team_name" TO "faction_name";--> statement-breakpoint -ALTER TABLE "faction" DROP CONSTRAINT "faction_team_name_unique";--> statement-breakpoint -ALTER TABLE "user" ADD COLUMN "discord_id" text;--> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToPermanence" ADD CONSTRAINT "userToPermanence_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "userToPermanence" ADD CONSTRAINT "userToPermanence_perm_id_permanence_id_fk" FOREIGN KEY ("perm_id") REFERENCES "permanence"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -ALTER TABLE "faction" ADD CONSTRAINT "faction_faction_name_unique" UNIQUE("faction_name"); \ No newline at end of file diff --git a/backend/drizzle/0014_curved_red_ghost.sql b/backend/drizzle/0014_curved_red_ghost.sql deleted file mode 100644 index e62a5d7e..00000000 --- a/backend/drizzle/0014_curved_red_ghost.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE "newstudent" DROP CONSTRAINT "newstudent_user_id_user_id_fk"; ---> statement-breakpoint -ALTER TABLE "newstudent" ADD COLUMN "email" text NOT NULL;--> statement-breakpoint -ALTER TABLE "newstudent" DROP COLUMN IF EXISTS "user_id";--> statement-breakpoint -ALTER TABLE "newstudent" ADD CONSTRAINT "newstudent_email_unique" UNIQUE("email"); \ No newline at end of file diff --git a/backend/drizzle/meta/0000_snapshot.json b/backend/drizzle/meta/0000_snapshot.json deleted file mode 100644 index 171618b7..00000000 --- a/backend/drizzle/meta/0000_snapshot.json +++ /dev/null @@ -1,429 +0,0 @@ -{ - "id": "a6eb0ed2-598a-471d-9b78-9f44ceb73ce2", - "prevId": "00000000-0000-0000-0000-000000000000", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0001_snapshot.json b/backend/drizzle/meta/0001_snapshot.json deleted file mode 100644 index 622d19e8..00000000 --- a/backend/drizzle/meta/0001_snapshot.json +++ /dev/null @@ -1,429 +0,0 @@ -{ - "id": "cd373bf5-fb40-4384-a361-f37ea0afc9fb", - "prevId": "a6eb0ed2-598a-471d-9b78-9f44ceb73ce2", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0002_snapshot.json b/backend/drizzle/meta/0002_snapshot.json deleted file mode 100644 index 64e71196..00000000 --- a/backend/drizzle/meta/0002_snapshot.json +++ /dev/null @@ -1,429 +0,0 @@ -{ - "id": "3abb5177-9b9f-4729-b952-35a89b5f16f7", - "prevId": "cd373bf5-fb40-4384-a361-f37ea0afc9fb", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0003_snapshot.json b/backend/drizzle/meta/0003_snapshot.json deleted file mode 100644 index 8d22e5e5..00000000 --- a/backend/drizzle/meta/0003_snapshot.json +++ /dev/null @@ -1,429 +0,0 @@ -{ - "id": "c72cd2fe-6974-44bb-809b-da4fbdc147c1", - "prevId": "3abb5177-9b9f-4729-b952-35a89b5f16f7", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0004_snapshot.json b/backend/drizzle/meta/0004_snapshot.json deleted file mode 100644 index 23b10dc5..00000000 --- a/backend/drizzle/meta/0004_snapshot.json +++ /dev/null @@ -1,429 +0,0 @@ -{ - "id": "d0fbf3c8-ed48-4086-8660-fe1ca1e984d1", - "prevId": "c72cd2fe-6974-44bb-809b-da4fbdc147c1", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0005_snapshot.json b/backend/drizzle/meta/0005_snapshot.json deleted file mode 100644 index 77005997..00000000 --- a/backend/drizzle/meta/0005_snapshot.json +++ /dev/null @@ -1,429 +0,0 @@ -{ - "id": "5ffd61bf-3f96-439b-8c60-a3671ca2d3c3", - "prevId": "d0fbf3c8-ed48-4086-8660-fe1ca1e984d1", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0006_snapshot.json b/backend/drizzle/meta/0006_snapshot.json deleted file mode 100644 index 9692063d..00000000 --- a/backend/drizzle/meta/0006_snapshot.json +++ /dev/null @@ -1,435 +0,0 @@ -{ - "id": "42ff6a57-5d16-43c8-b669-798912d4d9fa", - "prevId": "5ffd61bf-3f96-439b-8c60-a3671ca2d3c3", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0007_snapshot.json b/backend/drizzle/meta/0007_snapshot.json deleted file mode 100644 index 28e344ac..00000000 --- a/backend/drizzle/meta/0007_snapshot.json +++ /dev/null @@ -1,478 +0,0 @@ -{ - "id": "b487f454-b569-4751-a833-6350af78cff0", - "prevId": "42ff6a57-5d16-43c8-b669-798912d4d9fa", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "newstudentUUID": { - "name": "newstudentUUID", - "schema": "", - "columns": { - "uiid": { - "name": "uiid", - "type": "uuid", - "primaryKey": true, - "notNull": true - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "newstudentUUID_user_id_user_id_fk": { - "name": "newstudentUUID_user_id_user_id_fk", - "tableFrom": "newstudentUUID", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0008_snapshot.json b/backend/drizzle/meta/0008_snapshot.json deleted file mode 100644 index e189996a..00000000 --- a/backend/drizzle/meta/0008_snapshot.json +++ /dev/null @@ -1,479 +0,0 @@ -{ - "id": "4d4aeed9-4492-4303-92d7-ecae173ed84f", - "prevId": "b487f454-b569-4751-a833-6350af78cff0", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "newstudentUUID": { - "name": "newstudentUUID", - "schema": "", - "columns": { - "uiid": { - "name": "uiid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "newstudentUUID_user_id_user_id_fk": { - "name": "newstudentUUID_user_id_user_id_fk", - "tableFrom": "newstudentUUID", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0009_snapshot.json b/backend/drizzle/meta/0009_snapshot.json deleted file mode 100644 index 66b5690d..00000000 --- a/backend/drizzle/meta/0009_snapshot.json +++ /dev/null @@ -1,479 +0,0 @@ -{ - "id": "99a03e1c-5053-48e2-994d-4b7d6e8acdd3", - "prevId": "4d4aeed9-4492-4303-92d7-ecae173ed84f", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "newstudent": { - "name": "newstudent", - "schema": "", - "columns": { - "uuid": { - "name": "uuid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "newstudent_user_id_user_id_fk": { - "name": "newstudent_user_id_user_id_fk", - "tableFrom": "newstudent", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0010_snapshot.json b/backend/drizzle/meta/0010_snapshot.json deleted file mode 100644 index 30841cd2..00000000 --- a/backend/drizzle/meta/0010_snapshot.json +++ /dev/null @@ -1,485 +0,0 @@ -{ - "id": "b10c3708-4e2a-47ef-9596-b8b1101c53f6", - "prevId": "99a03e1c-5053-48e2-994d-4b7d6e8acdd3", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "newstudent": { - "name": "newstudent", - "schema": "", - "columns": { - "uuid": { - "name": "uuid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "newstudent_user_id_user_id_fk": { - "name": "newstudent_user_id_user_id_fk", - "tableFrom": "newstudent", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "branch": { - "name": "branch", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0011_snapshot.json b/backend/drizzle/meta/0011_snapshot.json deleted file mode 100644 index 6803eb69..00000000 --- a/backend/drizzle/meta/0011_snapshot.json +++ /dev/null @@ -1,662 +0,0 @@ -{ - "id": "fc1d1d52-59e5-4a7d-972f-424eda5d471e", - "prevId": "b10c3708-4e2a-47ef-9596-b8b1101c53f6", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "faction_name": { - "name": "faction_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "desc": { - "name": "desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "startingTime": { - "name": "startingTime", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "duartion": { - "name": "duartion", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "studenNumber": { - "name": "studenNumber", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_name_unique": { - "name": "faction_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - }, - "faction_desc_unique": { - "name": "faction_desc_unique", - "nullsNotDistinct": false, - "columns": [ - "desc" - ] - } - } - }, - "newstudent": { - "name": "newstudent", - "schema": "", - "columns": { - "uuid": { - "name": "uuid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "newstudent_user_id_user_id_fk": { - "name": "newstudent_user_id_user_id_fk", - "tableFrom": "newstudent", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "permanence": { - "name": "permanence", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "desc": { - "name": "desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "startingTime": { - "name": "startingTime", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "duartion": { - "name": "duartion", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "studenNumber": { - "name": "studenNumber", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "permanence_name_unique": { - "name": "permanence_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - }, - "permanence_desc_unique": { - "name": "permanence_desc_unique", - "nullsNotDistinct": false, - "columns": [ - "desc" - ] - } - } - }, - "userToPermanence": { - "name": "userToPermanence", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "perm_id": { - "name": "perm_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToPermanence_user_id_user_id_fk": { - "name": "userToPermanence_user_id_user_id_fk", - "tableFrom": "userToPermanence", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToPermanence_perm_id_permanence_id_fk": { - "name": "userToPermanence_perm_id_permanence_id_fk", - "tableFrom": "userToPermanence", - "tableTo": "permanence", - "columnsFrom": [ - "perm_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "branch": { - "name": "branch", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "discord_id": { - "name": "discord_id", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0012_snapshot.json b/backend/drizzle/meta/0012_snapshot.json deleted file mode 100644 index 164e9fcf..00000000 --- a/backend/drizzle/meta/0012_snapshot.json +++ /dev/null @@ -1,539 +0,0 @@ -{ - "id": "a4c1bccd-bfb7-4633-ac6c-7f90f62030c3", - "prevId": "fc1d1d52-59e5-4a7d-972f-424eda5d471e", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_team_name_unique": { - "name": "faction_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "newstudent": { - "name": "newstudent", - "schema": "", - "columns": { - "uuid": { - "name": "uuid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "newstudent_user_id_user_id_fk": { - "name": "newstudent_user_id_user_id_fk", - "tableFrom": "newstudent", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "permanence": { - "name": "permanence", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "desc": { - "name": "desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "startingTime": { - "name": "startingTime", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "duration": { - "name": "duration", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "studentNumber": { - "name": "studentNumber", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "permanence_name_unique": { - "name": "permanence_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "branch": { - "name": "branch", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0013_snapshot.json b/backend/drizzle/meta/0013_snapshot.json deleted file mode 100644 index 6f2500e8..00000000 --- a/backend/drizzle/meta/0013_snapshot.json +++ /dev/null @@ -1,594 +0,0 @@ -{ - "id": "ec2d7b66-e8ae-47c3-b24b-ca0950714125", - "prevId": "a4c1bccd-bfb7-4633-ac6c-7f90f62030c3", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "faction_name": { - "name": "faction_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_faction_name_unique": { - "name": "faction_faction_name_unique", - "nullsNotDistinct": false, - "columns": [ - "faction_name" - ] - } - } - }, - "newstudent": { - "name": "newstudent", - "schema": "", - "columns": { - "uuid": { - "name": "uuid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "newstudent_user_id_user_id_fk": { - "name": "newstudent_user_id_user_id_fk", - "tableFrom": "newstudent", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "permanence": { - "name": "permanence", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "desc": { - "name": "desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "startingTime": { - "name": "startingTime", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "duration": { - "name": "duration", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "studentNumber": { - "name": "studentNumber", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "permanence_name_unique": { - "name": "permanence_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "userToPermanence": { - "name": "userToPermanence", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "perm_id": { - "name": "perm_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToPermanence_user_id_user_id_fk": { - "name": "userToPermanence_user_id_user_id_fk", - "tableFrom": "userToPermanence", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToPermanence_perm_id_permanence_id_fk": { - "name": "userToPermanence_perm_id_permanence_id_fk", - "tableFrom": "userToPermanence", - "tableTo": "permanence", - "columnsFrom": [ - "perm_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "branch": { - "name": "branch", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "discord_id": { - "name": "discord_id", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/0014_snapshot.json b/backend/drizzle/meta/0014_snapshot.json deleted file mode 100644 index ed393b4f..00000000 --- a/backend/drizzle/meta/0014_snapshot.json +++ /dev/null @@ -1,588 +0,0 @@ -{ - "id": "cc69fdb5-5879-4bce-b5a4-791804201abc", - "prevId": "ec2d7b66-e8ae-47c3-b24b-ca0950714125", - "version": "5", - "dialect": "pg", - "tables": { - "challenge": { - "name": "challenge", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "challenge_name": { - "name": "challenge_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "challenge_desc": { - "name": "challenge_desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "challenge_challenge_name_unique": { - "name": "challenge_challenge_name_unique", - "nullsNotDistinct": false, - "columns": [ - "challenge_name" - ] - } - } - }, - "factionTochallenge": { - "name": "factionTochallenge", - "schema": "", - "columns": { - "faction_id": { - "name": "faction_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "challenge_id": { - "name": "challenge_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "factionTochallenge_faction_id_faction_id_fk": { - "name": "factionTochallenge_faction_id_faction_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "faction", - "columnsFrom": [ - "faction_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "factionTochallenge_challenge_id_challenge_id_fk": { - "name": "factionTochallenge_challenge_id_challenge_id_fk", - "tableFrom": "factionTochallenge", - "tableTo": "challenge", - "columnsFrom": [ - "challenge_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "event": { - "name": "event", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "event_name": { - "name": "event_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "state": { - "name": "state", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "event_event_name_unique": { - "name": "event_event_name_unique", - "nullsNotDistinct": false, - "columns": [ - "event_name" - ] - } - } - }, - "faction": { - "name": "faction", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "faction_name": { - "name": "faction_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "faction_faction_name_unique": { - "name": "faction_faction_name_unique", - "nullsNotDistinct": false, - "columns": [ - "faction_name" - ] - } - } - }, - "newstudent": { - "name": "newstudent", - "schema": "", - "columns": { - "uuid": { - "name": "uuid", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "isUsed": { - "name": "isUsed", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "newstudent_email_unique": { - "name": "newstudent_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - }, - "permanence": { - "name": "permanence", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "desc": { - "name": "desc", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "startingTime": { - "name": "startingTime", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "duration": { - "name": "duration", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "studentNumber": { - "name": "studentNumber", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "permanence_name_unique": { - "name": "permanence_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "userToPermanence": { - "name": "userToPermanence", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "perm_id": { - "name": "perm_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToPermanence_user_id_user_id_fk": { - "name": "userToPermanence_user_id_user_id_fk", - "tableFrom": "userToPermanence", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToPermanence_perm_id_permanence_id_fk": { - "name": "userToPermanence_perm_id_permanence_id_fk", - "tableFrom": "userToPermanence", - "tableTo": "permanence", - "columnsFrom": [ - "perm_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "role_name": { - "name": "role_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "role_desc": { - "name": "role_desc", - "type": "text", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_role_name_unique": { - "name": "role_role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "role_name" - ] - } - } - }, - "userToRole": { - "name": "userToRole", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "isWish": { - "name": "isWish", - "type": "boolean", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "userToRole_user_id_user_id_fk": { - "name": "userToRole_user_id_user_id_fk", - "tableFrom": "userToRole", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "userToRole_role_id_role_id_fk": { - "name": "userToRole_role_id_role_id_fk", - "tableFrom": "userToRole", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "team": { - "name": "team", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "isOfficial": { - "name": "isOfficial", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "timeCode": { - "name": "timeCode", - "type": "bigint", - "primaryKey": false, - "notNull": false - }, - "team_name": { - "name": "team_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "city_id": { - "name": "city_id", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "team_city_id_faction_id_fk": { - "name": "team_city_id_faction_id_fk", - "tableFrom": "team", - "tableTo": "faction", - "columnsFrom": [ - "city_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "team_team_name_unique": { - "name": "team_team_name_unique", - "nullsNotDistinct": false, - "columns": [ - "team_name" - ] - } - } - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "first_name": { - "name": "first_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "last_name": { - "name": "last_name", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "branch": { - "name": "branch", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "birthday": { - "name": "birthday", - "type": "date", - "primaryKey": false, - "notNull": false - }, - "contact": { - "name": "contact", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "discord_id": { - "name": "discord_id", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "connection_num": { - "name": "connection_num", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "permission": { - "name": "permission", - "type": "permission", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "team": { - "name": "team", - "type": "integer", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "user_team_team_id_fk": { - "name": "user_team_team_id_fk", - "tableFrom": "user", - "tableTo": "team", - "columnsFrom": [ - "team" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": { - "permission": { - "name": "permission", - "values": { - "newStudent": "newStudent", - "Student": "Student", - "Admin": "Admin", - "RespoCE": "RespoCE", - "Respo": "Respo", - "Anim": "Anim" - } - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/backend/drizzle/meta/_journal.json b/backend/drizzle/meta/_journal.json index 489b131f..c7c3250b 100644 --- a/backend/drizzle/meta/_journal.json +++ b/backend/drizzle/meta/_journal.json @@ -5,127 +5,15 @@ { "idx": 0, "version": "5", - "when": 1712611554924, - "tag": "0000_luxuriant_mandrill", + "when": 1723458432056, + "tag": "0000_wealthy_hellfire_club", "breakpoints": true }, { "idx": 1, "version": "5", - "when": 1713011110190, - "tag": "0001_bright_strong_guy", - "breakpoints": true - }, - { - "idx": 2, - "version": "5", - "when": 1713011230279, - "tag": "0002_large_mulholland_black", - "breakpoints": true - }, - { - "idx": 3, - "version": "5", - "when": 1713011739381, - "tag": "0003_odd_beyonder", - "breakpoints": true - }, - { - "idx": 4, - "version": "5", - "when": 1713011834737, - "tag": "0004_fluffy_kate_bishop", - "breakpoints": true - }, - { - "idx": 5, - "version": "5", - "when": 1713020099457, - "tag": "0005_quick_doorman", - "breakpoints": true - }, - { - "idx": 6, - "version": "5", - "when": 1718178424536, - "tag": "0006_huge_pride", - "breakpoints": true - }, - { - "idx": 7, - "version": "5", - "when": 1718916126040, - "tag": "0007_brief_joseph", - "breakpoints": true - }, - { - "idx": 8, - "version": "5", - "when": 1718920925767, - "tag": "0008_cheerful_titanium_man", - "breakpoints": true - }, - { - "idx": 9, - "version": "5", - "when": 1719818625531, - "tag": "0009_awesome_vermin", - "breakpoints": true - }, - { - "idx": 10, - "version": "5", - "when": 1720111045424, - "tag": "0010_sad_redwing", - "breakpoints": true - }, - { - "idx": 11, - "version": "5", - "when": 1720700501555, - "tag": "0011_jittery_nekra", - "breakpoints": true - }, - { - "idx": 12, - "version": "5", - "when": 1721050358124, - "tag": "0012_chilly_squadron_sinister", - "breakpoints": true - }, - { - "idx": 13, - "version": "5", - "when": 1721069761838, - "tag": "0013_acoustic_gabe_jones", - "breakpoints": true - }, - { - "idx": 14, - "version": "5", - "when": 1722348395029, - "tag": "0014_curved_red_ghost", - "breakpoints": true - }, - { - "idx": 15, - "version": "5", - "when": 1722506975111, - "tag": "0015_oval_scarlet_witch", - "breakpoints": true - }, - { - "idx": 16, - "version": "5", - "when": 1722507083789, - "tag": "0016_lumpy_ghost_rider", - "breakpoints": true - }, - { - "idx": 17, - "version": "5", - "when": 1722507507447, - "tag": "0017_redundant_speed_demon", + "when": 1723472551183, + "tag": "0001_robust_iron_patriot", "breakpoints": true } ] From 8d71cd9a5be7d2dcc3d3796c9270dd8c8fa3b778 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Fri, 16 Aug 2024 23:05:13 +0200 Subject: [PATCH 06/15] volume dans le docker-compose --- backend/docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml index ce56c2ac..91a541a3 100644 --- a/backend/docker-compose.yml +++ b/backend/docker-compose.yml @@ -8,6 +8,8 @@ services: - POSTGRES_DB=db - POSTGRES_USER=admin - POSTGRES_PASSWORD=password + volumes: + - ./data/postgres:/var/lib/postgresql/data networks: - docker-service From 1f141638edc4926503d90bde80ae7d531a41caf6 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Fri, 16 Aug 2024 23:05:42 +0200 Subject: [PATCH 07/15] =?UTF-8?q?D=C3=A9v=20en=20partie=20fini=20des=20d?= =?UTF-8?q?=C3=A9fis.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package-lock.json | 28 +- backend/package.json | 3 +- .../src/controllers/challenge.controller.ts | 71 ++++- backend/src/middlewares/permissions.ts | 20 ++ backend/src/routes/challenge.routes.ts | 16 ++ backend/src/schemas/challenge.schema.ts | 37 ++- backend/src/server.ts | 2 + backend/src/services/challenge.service.ts | 269 ++++++++++++++---- backend/src/utils/challenge.ts | 21 ++ .../src/components/challenge/AnimSection.tsx | 39 +++ .../components/challenge/faction/Actions.tsx | 129 +++++++++ .../challenge/faction/ChallFactionSection.tsx | 50 ++++ .../src/components/challenge/team/Actions.tsx | 98 +++++++ .../challenge/team/ChallTeamSection.tsx | 50 ++++ frontend/src/components/utils/Select.tsx | 32 ++- frontend/src/screens/Challenges.tsx | 33 ++- frontend/src/services/interfaces.ts | 16 ++ frontend/src/services/requests.ts | 7 + frontend/src/services/requests/challenges.ts | 29 ++ frontend/src/services/requests/teams.ts | 1 + 20 files changed, 877 insertions(+), 74 deletions(-) create mode 100644 backend/src/routes/challenge.routes.ts create mode 100644 backend/src/utils/challenge.ts create mode 100644 frontend/src/components/challenge/AnimSection.tsx create mode 100644 frontend/src/components/challenge/faction/Actions.tsx create mode 100644 frontend/src/components/challenge/faction/ChallFactionSection.tsx create mode 100644 frontend/src/components/challenge/team/Actions.tsx create mode 100644 frontend/src/components/challenge/team/ChallTeamSection.tsx create mode 100644 frontend/src/services/requests/challenges.ts diff --git a/backend/package-lock.json b/backend/package-lock.json index 15292ffa..74034c76 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -16,6 +16,7 @@ "axios": "^1.6.8", "bcryptjs": "^2.4.3", "cors": "^2.8.5", + "csv-parser": "^3.0.0", "dotenv": "^16.4.1", "drizzle-orm": "^0.29.3", "express": "^4.18.2", @@ -24,7 +25,7 @@ "nodemailer": "^6.9.14", "nodemon": "^3.0.3", "papaparse": "^5.4.1", - "pg": "^8.11.3", + "pg": "^8.12.0", "pg-promise": "^11.5.4", "postgres": "^3.4.3", "querystring": "^0.2.1", @@ -1480,6 +1481,21 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, + "node_modules/csv-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/csv-parser/-/csv-parser-3.0.0.tgz", + "integrity": "sha512-s6OYSXAK3IdKqYO33y09jhypG/bSDHPuyCme/IdEHfWpLf/jKcpitVFyOC6UemgGk8v7Q5u2XE0vvwmanxhGlQ==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.0" + }, + "bin": { + "csv-parser": "bin/csv-parser" + }, + "engines": { + "node": ">= 10" + } + }, "node_modules/d": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", @@ -2693,6 +2709,15 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -2861,6 +2886,7 @@ "version": "8.12.0", "resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", "integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", + "license": "MIT", "dependencies": { "pg-connection-string": "^2.6.4", "pg-pool": "^3.6.2", diff --git a/backend/package.json b/backend/package.json index aa46a4d4..7e5fea13 100644 --- a/backend/package.json +++ b/backend/package.json @@ -22,6 +22,7 @@ "axios": "^1.6.8", "bcryptjs": "^2.4.3", "cors": "^2.8.5", + "csv-parser": "^3.0.0", "dotenv": "^16.4.1", "drizzle-orm": "^0.29.3", "express": "^4.18.2", @@ -30,7 +31,7 @@ "nodemailer": "^6.9.14", "nodemon": "^3.0.3", "papaparse": "^5.4.1", - "pg": "^8.11.3", + "pg": "^8.12.0", "pg-promise": "^11.5.4", "postgres": "^3.4.3", "querystring": "^0.2.1", diff --git a/backend/src/controllers/challenge.controller.ts b/backend/src/controllers/challenge.controller.ts index 95cd8e82..4dee485c 100644 --- a/backend/src/controllers/challenge.controller.ts +++ b/backend/src/controllers/challenge.controller.ts @@ -11,6 +11,63 @@ export const getAllChallenges = async (req: Request, res: Response, next: NextFu } } +export const getAllStudentOrCeChallenges = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllStudentOrCeChallenges(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + +export const validChallenge = async (req: Request, res: Response, next: NextFunction) => { + try { + const {challId, associatedId, attributedPoints, text} = req.body + console.log(req.body) + const data = await service.validateChallenge(challId, associatedId, attributedPoints, text); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + +export const unvalidChallenge = async (req: Request, res: Response, next: NextFunction) => { + try { + const {challId, associatedId} = req.body + const data = await service.unvalidateChallenge(challId, associatedId); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + +export const getAllStudentChallenges = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllStudentChallenges(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + +export const getAllFactionChallenges = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllFactionChallenges(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + +export const getAllTeamChallenges = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllTeamChallenges(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + export const createChallenge = async (req: Request, res: Response, next: NextFunction) => { const { name, desc, points } = req.body; name ?? Error(res, { msg: "No name" }); @@ -38,12 +95,22 @@ export const deleteChallenge = async (req: Request, res: Response, next: NextFun }; export const validateChallenge = async (req: Request, res: Response, next: NextFunction) => { - const { challengeId, associatedId, points } = req.body; + const { challengeId, associatedId, points, text } = req.body; try { - await service.validateChallenge(challengeId, associatedId, points); + await service.validateChallenge(challengeId, associatedId, points, text); Ok(res, { msg: "challenge validated" }); } catch (error) { Error(res, { error }); } } + +export const countPoints = async (req: Request, res: Response, next: NextFunction) => { + + try { + const points = [await service.countPoints(1), await service.countPoints(2)] + Ok(res, {data: points}); + } catch (error) { + Error(res, { error }); + } +} \ No newline at end of file diff --git a/backend/src/middlewares/permissions.ts b/backend/src/middlewares/permissions.ts index 09874eb5..d8841a34 100644 --- a/backend/src/middlewares/permissions.ts +++ b/backend/src/middlewares/permissions.ts @@ -42,6 +42,26 @@ export const isAdminCE = async (req: Request, res: Response, next: NextFunction) } }; +//TODO: create anim perm +export const isAdminAnim = async (req: Request, res: Response, next: NextFunction) => { + try { + const decodedToken = decodeToken(req); + const user = await getUserByEmail(decodedToken.email); + + if (user === null) { + return Error(res, { msg: "user doesn't exists" }); + } + + if (user.permission === PermType.Admin || user.permission === PermType.RespoCE) { + next(); + } else { + Error(res, { msg: 'Forbidden: Insufficient permissions' }); + } + } catch (error) { + return Error(res, { msg: 'Unauthorized: Invalid token' }); + } +}; + export const isTokenValid = async (req: Request, res: Response, next: NextFunction) => { try { const token = req.headers['authorization']?.split(' ')[1]; diff --git a/backend/src/routes/challenge.routes.ts b/backend/src/routes/challenge.routes.ts new file mode 100644 index 00000000..80fbf805 --- /dev/null +++ b/backend/src/routes/challenge.routes.ts @@ -0,0 +1,16 @@ +import express from 'express'; +import * as fc from '../controllers/challenge.controller'; +import {isAdmin, isAdminAnim, isAdminCE} from '../middlewares/permissions'; + +const challengeRouter = express.Router(); + +challengeRouter.get('/countPoints', isAdminAnim, fc.countPoints); +challengeRouter.get('/all', fc.getAllChallenges); +challengeRouter.post('/valid', isAdminAnim, fc.validChallenge); +challengeRouter.post('/unvalid', isAdminAnim, fc.unvalidChallenge); +challengeRouter.get('/allFaction', fc.getAllFactionChallenges); +challengeRouter.get('/allStudent', fc.getAllStudentChallenges); +challengeRouter.get('/allTeam', fc.getAllTeamChallenges); +challengeRouter.get('/allStudentOrCe', fc.getAllStudentOrCeChallenges); + +export default challengeRouter; \ No newline at end of file diff --git a/backend/src/schemas/challenge.schema.ts b/backend/src/schemas/challenge.schema.ts index e6c7b61a..e0e94a20 100644 --- a/backend/src/schemas/challenge.schema.ts +++ b/backend/src/schemas/challenge.schema.ts @@ -1,6 +1,7 @@ import {pgTable, serial, text, integer, pgEnum} from "drizzle-orm/pg-core"; import { factionSchema } from "./faction.schema"; import {newstudentSchema} from "./newstudent.schema"; +import { primaryKey } from 'drizzle-orm/pg-core'; import {userSchema} from "./user.schema"; import {teamSchema} from "./team.schema"; @@ -49,25 +50,39 @@ export const challengeSchema = pgTable('challenge', { export type challenge = typeof challengeSchema.$inferInsert; export const factionTochallengeSchema = pgTable('factionTochallenge', { - factionId: integer('faction_id').notNull().primaryKey().references(() => factionSchema.id), - challengeId: integer('challenge_id').notNull().primaryKey().references(() => challengeSchema.id), + factionId: integer('faction_id').notNull().references(() => factionSchema.id), + challengeId: integer('challenge_id').notNull().references(() => challengeSchema.id), attributedPoints: integer('attributed_points').notNull(), -}); +}, (table) => ({ + pk: primaryKey(table.factionId, table.challengeId) // Clé primaire composite +})); export type factionTochallenge = typeof factionTochallengeSchema.$inferInsert; -export const TeamTochallengeSchema = pgTable('factionTochallenge', { - teamId: integer('team_id').notNull().primaryKey().references(() => teamSchema.id), - challengeId: integer('challenge_id').notNull().primaryKey().references(() => challengeSchema.id), +export const TeamTochallengeSchema = pgTable('teamTochallenge', { + teamId: integer('team_id').notNull().references(() => teamSchema.id), + challengeId: integer('challenge_id').notNull().references(() => challengeSchema.id), attributedPoints: integer('attributed_points').notNull(), -}); +}, (table) => ({ + pk: primaryKey(table.teamId, table.challengeId) // Clé primaire composite +})); -export type TeamTochallenge = typeof TeamTochallengeSchema.$inferInsert; +export type teamTochallenge = typeof TeamTochallengeSchema.$inferInsert; export const StudentTochallengeSchema = pgTable('studentTochallenge', { - studentId: integer('student_id').notNull().primaryKey().references(() => userSchema.id), - challengeId: integer('challenge_id').notNull().primaryKey().references(() => challengeSchema.id), + studentId: integer('student_id').notNull().references(() => userSchema.id), + challengeId: integer('challenge_id').notNull().references(() => challengeSchema.id), attributedPoints: integer('attributed_points').notNull(), -}); +}, (table) => ({ + pk: primaryKey(table.studentId, table.challengeId) // Clé primaire composite +})); export type studentTochallenge = typeof StudentTochallengeSchema.$inferInsert; + +export const FreeToChallengeSchema = pgTable('freeToChallenge', { + factionId: integer('faction_id').notNull().references(() => factionSchema.id), + text: text('text').notNull(), + attributedPoints: integer('attributed_points').notNull(), +}); + +export type freeToChallenge = typeof StudentTochallengeSchema.$inferInsert; diff --git a/backend/src/server.ts b/backend/src/server.ts index 542e41e6..e413a0ac 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -12,6 +12,7 @@ import { init } from "./database/init"; import { api_prefix } from "./utils/secret"; import { log } from "./middlewares/log"; import emailRouter from "./routes/email.routes"; +import challengeRouter from "./routes/challenge.routes"; async function startServer() { const app = express(); @@ -26,6 +27,7 @@ async function startServer() { router.use("/user", userRouter); router.use("/team", teamRouter); router.use("/permanence", permanenceRouter); + router.use("/challenge", challengeRouter); router.use("/faction", factionRouter); router.use("/role", roleRouter); router.use("/event", eventRouter); diff --git a/backend/src/services/challenge.service.ts b/backend/src/services/challenge.service.ts index 516e4115..b16fa42b 100644 --- a/backend/src/services/challenge.service.ts +++ b/backend/src/services/challenge.service.ts @@ -3,12 +3,17 @@ import { challenge, factionTochallengeSchema, factionTochallenge, - ChallengeType, StudentTochallengeSchema + ChallengeType, StudentTochallengeSchema, TeamTochallengeSchema, freeToChallenge, FreeToChallengeSchema } from "../schemas/challenge.schema" import {addPoints, removePoints} from "./faction.service" import { db } from "../database/db" import {and, eq} from 'drizzle-orm' -import {userSchema} from "../schemas/user.schema"; +import {PermType, userSchema} from "../schemas/user.schema"; +import {teamSchema} from "../schemas/team.schema"; +import {factionSchema} from "../schemas/faction.schema"; +import assert from "node:assert"; +import {getFactionFromUserId, getFactionFromUserTeam} from "../utils/challenge"; + export const getAllChallenges = async () => { try { @@ -18,6 +23,38 @@ export const getAllChallenges = async () => { } } +export const getAllFactionChallenges = async () => { + try { + return await db.select().from(challengeSchema).where(eq(challengeSchema.challType, ChallengeType.Faction)); + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + +export const getAllStudentOrCeChallenges = async () => { + try { + return await db.select().from(challengeSchema).where(eq(challengeSchema.challType, ChallengeType.StudentOrCe)); + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + +export const getAllTeamChallenges = async () => { + try { + return await db.select().from(challengeSchema).where(eq(challengeSchema.challType, ChallengeType.Team)); + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + +export const getAllStudentChallenges = async () => { + try { + return await db.select().from(challengeSchema).where(eq(challengeSchema.challType, ChallengeType.Student)); + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + export const getChallenge = async (id: number) => { try { const chall = await db.select().from(challengeSchema).where(eq(challengeSchema.id, id)) @@ -36,6 +73,38 @@ export const getFactionChallenges = async (factionId: number) => { } } +export const countPoints = async (factionId: number): Promise => { + //checking faction exist + const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, factionId)); + if(!faction || faction.length === 0) throw new Error("No faction with id '" + faction + "'") + + let points = 0; + + //getting every challenge associated with faction + const factionChallenges = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema.factionId, factionId)) + factionChallenges.forEach(challenge => points += challenge.attributedPoints) + + //getting every teamId who is associated with factionId + const factionTeams = await db.select().from(teamSchema).where(eq(teamSchema.faction, factionId)) + const teamsId = factionTeams.map(team => team.id) + + //getting every challenge associated with every teams and add points + //also getting every user associated with teamId + for (const teamId of teamsId) { + const challenges = await db.select().from(TeamTochallengeSchema).where(eq(TeamTochallengeSchema.teamId, teamId)); + challenges.forEach(challenge => points += challenge.attributedPoints) + //-----// + const users = await db.select().from(userSchema).where(eq(userSchema.team, teamId)); + //getting challenges associated to users + for(let user of users) { + const userChallenges = await db.select().from(StudentTochallengeSchema).where(eq(StudentTochallengeSchema.studentId, user.id)) + userChallenges.forEach(challenge => points += challenge.attributedPoints) + } + } + + return points +} + export const createChallenge = async (name: string, description: string, points: string, challType: ChallengeType) => { const newChallenge: challenge = {name: name, description: description, points: points, challType: challType}; try { @@ -54,71 +123,173 @@ export const deleteChallenge = async (id: number) => { } } -export const validateChallenge = async (challengeId: number, associatedId: number, attributedPoints: number) => { +export const validateChallenge = async (challengeId: number, associatedId: number, attributedPoints: number, text: string | null) => { + console.log("Cc") //First get the type of challenge const challenge = await db.select().from(challengeSchema).where(eq(challengeSchema.id, challengeId)); if(!challenge || challenge.length === 0) throw new Error("No challenge with id '" + challengeId + "'") const challType: ChallengeType = challenge[0].challType switch (challType) { case ChallengeType.Student: - //means associatedId is a student - //checking user exist - const user = await db.select().from(userSchema).where(eq(userSchema.id, associatedId)); - if(!user || user.length === 0) throw new Error("No user with id '" + associatedId + "'") - //check user is not CE - if(user[0].permission === ) - //Associating the challenge to the user - //checking is event already associated with this user - const associatedChall = await db.select().from(StudentTochallengeSchema) - .where( - and( - eq(StudentTochallengeSchema.challengeId, challengeId), - eq(StudentTochallengeSchema.studentId, associatedId) - ) - ); - - if(associatedChall) throw new Error("Event already associated with this user. userId '" + associatedId + "'") - //associating the event - await db.insert(StudentTochallengeSchema).values({ - challengeId: challengeId, - studentId: associatedId, - attributedPoints: attributedPoints - }).execute(); + await completeChallengeToUser(challengeId, associatedId, attributedPoints, false) break; case ChallengeType.StudentOrCe: + await completeChallengeToUser(challengeId, associatedId, attributedPoints, true) break; case ChallengeType.Team: + await completeChallengeToTeam(challengeId, associatedId, attributedPoints) break; case ChallengeType.Faction: + await completeChallengeToFaction(challengeId, associatedId, attributedPoints) break; case ChallengeType.Free: + if(!text) throw new Error("You need to explain why you add points.") + await freeChallengeToFaction(associatedId, attributedPoints, text) break; } - const newFacToChall: factionTochallenge = { challengeId, factionId: associatedId, attributedPoints}; - const alreadyValidate = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema, newFacToChall)); - //if(alreadyValidate.length > 0) throw new Error(`Challenge ${challengeId} already validated for team ${factionId}.`) - if (!alreadyValidate || alreadyValidate.length === 0) { - await addPoints(associatedId, attributedPoints); - await db.insert(factionTochallengeSchema).values(newFacToChall); +} + + +//TODO +export const unvalidateChallenge = async (challengeId: number, associatedId: number) => { + //First get the type of challenge + const challenge = await db.select().from(challengeSchema).where(eq(challengeSchema.id, challengeId)); + if(!challenge || challenge.length === 0) throw new Error("No challenge with id '" + challengeId + "'") + const challType: ChallengeType = challenge[0].challType + switch (challType) { + case ChallengeType.Student: + await unvalidateChallengeToUser(challengeId, associatedId) + break; + case ChallengeType.StudentOrCe: + await unvalidateChallengeToUser(challengeId, associatedId) + break; + case ChallengeType.Team: + await unvalidateChallengeToTeam(challengeId, associatedId) + break; + case ChallengeType.Faction: + await unvalidateChallengeToFaction(challengeId, associatedId) + break; + case ChallengeType.Free: + await unvalidateToFaction(associatedId) + break; } } -export const unvalidateChallenge = async (challengeId: number, factionId: number) => { - try { - const newFacToChall = { challengeId, factionId}; - const alreadyValidate = await db.select() - .from(factionTochallengeSchema) - .where( - and( - eq(factionTochallengeSchema.challengeId, challengeId), - eq(factionTochallengeSchema.factionId, factionId) - ) - ); - if (alreadyValidate.length > 0) { - await removePoints(factionId, alreadyValidate[0].attributedPoints); - await db.delete(factionTochallengeSchema).where(eq(factionTochallengeSchema, alreadyValidate[0])) - } - } catch (error) { - throw new Error("Failed to create challenge to faction. Please try again later."); +async function unvalidateChallengeToUser(challengeId: number, associatedId: number) { + //Getting the challenge + const associatedChall = await db.select().from(StudentTochallengeSchema) + .where( + and( + eq(StudentTochallengeSchema.challengeId, challengeId), + eq(StudentTochallengeSchema.studentId, associatedId) + ) + ); + if(associatedChall.length === 0) throw new Error("Event already associated with this user. userId '" + associatedId + "'") + const points = associatedChall[0].attributedPoints + //Getting faction + const faction = await getFactionFromUserId(associatedId) + await removePoints(faction, points) +} + +async function completeChallengeToUser(challengeId: number, associatedId: number, attributedPoints: number, allowCe: boolean) { + //means associatedId is a student + //checking user exist + const user = await db.select().from(userSchema).where(eq(userSchema.id, associatedId)); + if(!user || user.length === 0) throw new Error("No user with id '" + associatedId + "'") + //check user is not CE + if(!allowCe) { + if(user[0].permission === PermType.Student && user[0].team !== null) throw new Error("User is 'CE' he can not complete this challenge.") } + //Associating the challenge to the user + //checking is event already associated with this user + const associatedChall = await db.select().from(StudentTochallengeSchema) + .where( + and( + eq(StudentTochallengeSchema.challengeId, challengeId), + eq(StudentTochallengeSchema.studentId, associatedId) + ) + ); + + if(associatedChall && associatedChall.length > 0) throw new Error("Event already associated with this user. userId '" + associatedId + "'") + //associating the event + await db.insert(StudentTochallengeSchema).values({ + challengeId: challengeId, + studentId: associatedId, + attributedPoints: attributedPoints + }).execute(); + + //get associated faction + const faction = await getFactionFromUserTeam(user[0].team as number) + await addPoints(faction, attributedPoints) +} + +async function completeChallengeToTeam(challengeId: number, associatedId: number, attributedPoints: number) { + //means associatedId is a team + //checking team exist + const team = await db.select().from(teamSchema).where(eq(teamSchema.id, associatedId)); + if(!team || team.length === 0) throw new Error("No team with id '" + associatedId + "'") + //Associating the challenge to the team + //checking is event already associated with this team + const associatedChall = await db.select().from(TeamTochallengeSchema) + .where( + and( + eq(TeamTochallengeSchema.challengeId, challengeId), + eq(TeamTochallengeSchema.teamId, associatedId) + ) + ); + + if(associatedChall && associatedChall.length > 0) throw new Error("Event already associated with this team. teamId '" + associatedId + "'") + //associating the event + await db.insert(TeamTochallengeSchema).values({ + challengeId: challengeId, + teamId: associatedId, + attributedPoints: attributedPoints + }).execute(); + + //adding points to the faction also + await addPoints(team[0].faction as number, attributedPoints) +} + +async function completeChallengeToFaction(challengeId: number, associatedId: number, attributedPoints: number) { + //means associatedId is a faction + //checking faction exist + const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, associatedId)); + if(!faction || faction.length === 0) throw new Error("No faction with id '" + associatedId + "'") + //Associating the challenge to the faction + //checking is event already associated with this faction + const associatedChall = await db.select().from(factionTochallengeSchema) + .where( + and( + eq(factionTochallengeSchema.challengeId, challengeId), + eq(factionTochallengeSchema.factionId, associatedId) + ) + ); + console.log(associatedChall) + if(associatedChall && associatedChall.length > 0) throw new Error("Event already associated with this faction. teamId '" + associatedId + "'") + //associating the event + await db.insert(factionTochallengeSchema).values({ + challengeId: challengeId, + factionId: associatedId, + attributedPoints: attributedPoints + }).execute(); + + //adding points to the faction also + await addPoints(faction[0].id, attributedPoints) +} + +async function freeChallengeToFaction(factionId: number, attributedPoints: number, text: string) { + //means associatedId is a faction + //checking faction exist + const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, factionId)); + if(!faction || faction.length === 0) throw new Error("No faction with id '" + faction + "'") + + //associating the event + await db.insert(FreeToChallengeSchema).values({ + factionId: factionId, + text: text, + attributedPoints: attributedPoints + }).execute(); + + //adding points to the faction also + await addPoints(faction[0].id, attributedPoints) } \ No newline at end of file diff --git a/backend/src/utils/challenge.ts b/backend/src/utils/challenge.ts new file mode 100644 index 00000000..303d362a --- /dev/null +++ b/backend/src/utils/challenge.ts @@ -0,0 +1,21 @@ +import {db} from "../database/db"; +import {teamSchema} from "../schemas/team.schema"; +import {eq} from "drizzle-orm"; +import {userSchema} from "../schemas/user.schema"; + +export async function getFactionFromUserTeam(userTeam: number): Promise { + //get associated faction + const team = await db.select().from(teamSchema).where(eq(teamSchema.id, userTeam)) + if(!team || team.length === 0) throw new Error('No team with id ' + userTeam) + return team[0].faction as number +} + +export async function getFactionFromUserId(userId: number): Promise { + //get user + const user = await db.select().from(userSchema).where(eq(userSchema.id, userId)) + if(!user || user.length === 0) throw new Error("No user with id '" + userId + "'") + //get associated faction + const team = await db.select().from(teamSchema).where(eq(teamSchema.id, user[0].team as number)) + if(!team || team.length === 0) throw new Error('No team with id ' + user[0].team) + return team[0].faction as number +} \ No newline at end of file diff --git a/frontend/src/components/challenge/AnimSection.tsx b/frontend/src/components/challenge/AnimSection.tsx new file mode 100644 index 00000000..df6f68cd --- /dev/null +++ b/frontend/src/components/challenge/AnimSection.tsx @@ -0,0 +1,39 @@ +import React, { useState } from 'react'; + +export interface AnimAction { + title: string; + form: JSX.Element; +} + +export interface SectionProps { + actions: AnimAction[]; +} + +const AnimSection: React.FC = ({ actions }) => { + const [selectedAction, setSelectedAction] = useState(null); + + const handleActionClick = (action: AnimAction) => { + setSelectedAction(action); + }; + + return ( +
+
+ {actions.map((action, index) => ( +
+ +
+ ))} +
+
+ {selectedAction && ( + selectedAction.form + )} +
+
+ ); +}; + +export default AnimSection; diff --git a/frontend/src/components/challenge/faction/Actions.tsx b/frontend/src/components/challenge/faction/Actions.tsx new file mode 100644 index 00000000..9908bf2f --- /dev/null +++ b/frontend/src/components/challenge/faction/Actions.tsx @@ -0,0 +1,129 @@ +import React, { useEffect, useState } from 'react'; +import Select from 'react-select' +import { + createTeam, + addToFaction, + deleteTeam, + getAllTeams, + renameTeam, + validateTeam, +} from '../../../services/requests/teams'; +import { ToastContainer, toast } from 'react-toastify'; +import "react-toastify/dist/ReactToastify.css"; +import {Challenge, ChallType} from "../../../services/interfaces"; +import {toTable} from "../../utils/Tables"; +import {getChallenges, unvalidChallenge, validChallenge} from "../../../services/requests/challenges"; +import {handleError, toId} from "../../utils/Submit"; +import {changePermission} from "../../../services/requests/users"; +import {Challenges, Factions, Users} from "../../utils/Select"; + +interface TableChallengeType { + type: ChallType +} + +export const TableChallenge: React.FC = ({ type }) => { + + const [challenges, setChallenges] = useState([]); + + useEffect(() => { + const fetchChallenges = async () => { + try { + const teams = await getChallenges(type); + setChallenges(teams) + } catch (error) { + console.error('Error fetching challenges:', error); + } + }; + fetchChallenges(); + }, []); + return challenges.length > 0 ? toTable(challenges) : null; +} + +export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [faction, setFaction] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + const [points, setPoints] = useState(0) + const [text, setText] = useState("") + + const Submit = async () => { + const id = toId(faction) + await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) + setFaction({}) + setChallenge({}) + setPoints(0) + setText("") + } + + return ( +
+
+ setChallenge(chall)} + value={challenge} + /> + +
+
+
+ + setPoints(Number(e.target.value))} + /> +
+ + {/* Input pour le texte */} +
+ + setText(e.target.value)} + /> +
+
+ + +
+ ) +} + +export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [faction, setFaction] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + + const Submit = async () => { + await handleError("Challenge validé !", "Challenge déjà complété.", unvalidChallenge, faction.value, challenge.value) + setFaction({}) + setChallenge({}) + } + + return ( +
+
+ setChallenge(chall)} + value={challenge} + /> + +
+ + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/challenge/faction/ChallFactionSection.tsx b/frontend/src/components/challenge/faction/ChallFactionSection.tsx new file mode 100644 index 00000000..25ab50a9 --- /dev/null +++ b/frontend/src/components/challenge/faction/ChallFactionSection.tsx @@ -0,0 +1,50 @@ +import React, {useEffect, useState} from 'react'; +import {TableChallenge, ValidChallenge} from './Actions'; +import {getRole} from '../../../services/requests'; +import AnimSection from "../AnimSection"; +import {AdminAction} from "../../admin/AdminSection"; +import {ChallType} from "../../../services/interfaces"; + +const ChallFactionSection: React.FC = () => { + + const [clicked, setClicked] = useState(false); + const [role, setRole] = useState(null); + + const handleClick = () => { + setClicked(!clicked); + } + + useEffect(() => { + const fetchRole = async () => { + try { + const role = await getRole(); + setRole(role); + } catch (error) { + console.error('Error fetching role:', error); + } + }; + + fetchRole(); + }, []); + + const actions: AdminAction[] = [ + { + title: 'Valider challenge', + form: , + }, + { + title: 'Unvalider challenge', + form: , + }, + { + title: 'Affichage challenges', + form: , + } + ]; + + return ( + + ); +}; + +export default ChallFactionSection; diff --git a/frontend/src/components/challenge/team/Actions.tsx b/frontend/src/components/challenge/team/Actions.tsx new file mode 100644 index 00000000..ffadf8dd --- /dev/null +++ b/frontend/src/components/challenge/team/Actions.tsx @@ -0,0 +1,98 @@ +import React, { useEffect, useState } from 'react'; +import Select from 'react-select' +import { + createTeam, + addToFaction, + deleteTeam, + getAllTeams, + renameTeam, + validateTeam, +} from '../../../services/requests/teams'; +import { ToastContainer, toast } from 'react-toastify'; +import "react-toastify/dist/ReactToastify.css"; +import {Challenge, ChallType} from "../../../services/interfaces"; +import {toTable} from "../../utils/Tables"; +import {getChallenges, validChallenge} from "../../../services/requests/challenges"; +import {handleError, toId} from "../../utils/Submit"; +import {changePermission} from "../../../services/requests/users"; +import {Challenges, Factions, Users} from "../../utils/Select"; + +interface TableChallengeType { + type: ChallType +} + +export const TableChallenge: React.FC = ({ type }) => { + + const [challenges, setChallenges] = useState([]); + + useEffect(() => { + const fetchChallenges = async () => { + try { + const teams = await getChallenges(type); + setChallenges(teams) + } catch (error) { + console.error('Error fetching challenges:', error); + } + }; + fetchChallenges(); + }, []); + return challenges.length > 0 ? toTable(challenges) : null; +} + +export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [faction, setFaction] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + const [points, setPoints] = useState(0) + const [text, setText] = useState("") + + const Submit = async () => { + const id = toId(faction) + await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) + setFaction({}) + setChallenge({}) + setPoints(0) + setText("") + } + + return ( +
+
+ setChallenge(chall)} + value={challenge} + /> + +
+
+
+ + setPoints(Number(e.target.value))} + /> +
+ + {/* Input pour le texte */} +
+ + setText(e.target.value)} + /> +
+
+ + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/challenge/team/ChallTeamSection.tsx b/frontend/src/components/challenge/team/ChallTeamSection.tsx new file mode 100644 index 00000000..24aa4b09 --- /dev/null +++ b/frontend/src/components/challenge/team/ChallTeamSection.tsx @@ -0,0 +1,50 @@ +import React, {useEffect, useState} from 'react'; +import {TableChallenge, ValidChallenge} from './Actions'; +import {getRole} from '../../../services/requests'; +import AnimSection from "../AnimSection"; +import {AdminAction} from "../../admin/AdminSection"; +import {ChallType} from "../../../services/interfaces"; + +const ChallTeamSection: React.FC = () => { + + const [clicked, setClicked] = useState(false); + const [role, setRole] = useState(null); + + const handleClick = () => { + setClicked(!clicked); + } + + useEffect(() => { + const fetchRole = async () => { + try { + const role = await getRole(); + setRole(role); + } catch (error) { + console.error('Error fetching role:', error); + } + }; + + fetchRole(); + }, []); + + const actions: AdminAction[] = [ + { + title: 'Valider challenge', + form: , + }, + { + title: 'Unvalider challenge', + form: , + }, + { + title: 'Affichage challenges', + form: , + } + ]; + + return ( + + ); +}; + +export default ChallTeamSection; diff --git a/frontend/src/components/utils/Select.tsx b/frontend/src/components/utils/Select.tsx index f09573f8..f0875a43 100644 --- a/frontend/src/components/utils/Select.tsx +++ b/frontend/src/components/utils/Select.tsx @@ -1,11 +1,12 @@ -import { useState, useEffect } from "react" -import { Role, Faction, User, Team, Event, newStudent, Perm } from '../../services/interfaces' +import React, { useState, useEffect } from "react" +import {Role, Faction, User, Team, Event, newStudent, Perm, Challenge, ChallType} from '../../services/interfaces' import { getAllFactions, getAllTeams, getAllUsers } from '../../services/requests' import { getAllRoles } from "../../services/requests/roles" import { getActiveEvents, getInactiveEvents } from "../../services/requests/events" import { getAllUUID } from "../../services/requests/newstudent" import { getAllPerms } from "../../services/requests/perms" import { getAllByPermission } from "../../services/requests/users" +import {getAllChallenges, getChallenges} from "../../services/requests/challenges"; export const Roles = () => { const [options, setOptions] = useState([]) @@ -100,6 +101,33 @@ export const Teams = () => { return options } +export const Challenges = (challType: ChallType) => { + const [options, setOptions] = useState([]) + + useEffect(() => { + const fetchData = async () => { + try { + const response = await getChallenges(challType) + const challOptions = response.map((chall: Challenge) => { + console.log(chall) + return { + value: chall.id, + label: chall.name, + } + }) + console.log(challOptions) + setOptions(challOptions) + } catch (error) { + console.error('Error fetching data:', error) + } + } + + fetchData() + }, []) + + return options +} + export const Users = () => { const [options, setOptions] = useState([]) diff --git a/frontend/src/screens/Challenges.tsx b/frontend/src/screens/Challenges.tsx index 18f49996..9f9a99de 100644 --- a/frontend/src/screens/Challenges.tsx +++ b/frontend/src/screens/Challenges.tsx @@ -1,19 +1,29 @@ import { Navbar } from "../components/shared/Navbar" -import { useEffect } from "react"; +import {useEffect, useState} from "react"; import { Section } from "../components/shared/Section"; import { Default } from "../components/shared/Default"; import { getCurrentUser } from "../services/requests/users"; +import UserAdminSection from "../components/admin/users/UserAdminSection"; +import AnimSection from "../components/challenge/AnimSection"; +import ChallFactionSection from "../components/challenge/faction/ChallFactionSection"; +import ChallTeamSection from "../components/challenge/team/ChallTeamSection"; export const Defis = () => { + const [permission, setPermission] = useState(null); + useEffect(() => { const fetchUser = async () => { try { const user = await getCurrentUser(); - const permission = user.permission - if (!permission) { - window.location.href = '/'; + const permission = user.permission; + + if ((permission !== ('Admin') && permission !== 'Anim')) { + console.log(permission) + window.location.href = '/Home'; return null; } + setPermission(permission); + } catch (error) { console.error('Error fetching permission:', error); } @@ -23,9 +33,16 @@ export const Defis = () => { }, []); return ( -
- -
+
+ +
+
) -} \ No newline at end of file +} + +/* +
+
+
+ */ \ No newline at end of file diff --git a/frontend/src/services/interfaces.ts b/frontend/src/services/interfaces.ts index 0be7577f..4dec7d92 100644 --- a/frontend/src/services/interfaces.ts +++ b/frontend/src/services/interfaces.ts @@ -19,6 +19,22 @@ export interface Team { faction:number; } +export enum ChallType { + Student = "Student", + StudentOrCe = "StudentOrCe", + Team = "Team", + Faction = "Faction", + Free = "Free" +} + +export interface Challenge { + id: number; + name: string; + description: string; + points: string; + chall_type: ChallType; +} + export interface Faction { id: number; name: string; diff --git a/frontend/src/services/requests.ts b/frontend/src/services/requests.ts index 6ea1828e..81e3433d 100644 --- a/frontend/src/services/requests.ts +++ b/frontend/src/services/requests.ts @@ -85,3 +85,10 @@ export const getWishUsers = async (roleId: string) => { const response = await api.get('/wish/' + roleId + '/users'); return response?.data.data; } + +// Compte les points d'une faction +export const countPoints = async () => { + const response = await api.get('/challenge/countPoints/'); + console.log(response?.data.data) + return response?.data.data; +} diff --git a/frontend/src/services/requests/challenges.ts b/frontend/src/services/requests/challenges.ts new file mode 100644 index 00000000..07ab4efe --- /dev/null +++ b/frontend/src/services/requests/challenges.ts @@ -0,0 +1,29 @@ +import { api } from "../api"; +import {ChallType} from "../interfaces"; + +// Obtention de la liste des challenges enregistrées dans la db +export const getAllChallenges = async () => { + const response = await api.get("challenge/all"); + return response.data.data; +}; + +export const getChallenges = async (type: ChallType) => { + const response = await api.get("challenge/all" + type); + return response.data.data; +}; + +export const validChallenge = async (associatedId: number, challId: number, attributedPoints: number, text: string|null) => { + return await api.post('challenge/valid', { + associatedId, + challId, + attributedPoints, + text + }) +} + +export const unvalidChallenge = async (associatedId: number, challId: number) => { + return await api.post('challenge/unvalid', { + associatedId, + challId + }) +} diff --git a/frontend/src/services/requests/teams.ts b/frontend/src/services/requests/teams.ts index cfc59a4c..b39677f9 100644 --- a/frontend/src/services/requests/teams.ts +++ b/frontend/src/services/requests/teams.ts @@ -1,4 +1,5 @@ import { api } from "../api"; +import {ChallType} from "../interfaces"; export const createTeam = async (name: string) => { return await api.post("team", { name }); From 2603e4eb1c5fe9e1ea9878a788a34bb505c59cef Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Mon, 19 Aug 2024 14:20:25 +0200 Subject: [PATCH 08/15] =?UTF-8?q?D=C3=A9fi=20finito=20(normalement,=20bism?= =?UTF-8?q?illah)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controllers/challenge.controller.ts | 41 +++++- backend/src/routes/challenge.routes.ts | 4 + backend/src/services/challenge.service.ts | 134 +++++++++++++++-- backend/src/services/faction.service.ts | 3 + .../components/challenge/faction/Actions.tsx | 14 +- .../challenge/faction/ChallFactionSection.tsx | 4 +- .../challenge/free/ChallFreeSection.tsx | 50 +++++++ .../components/challenge/free/FreeActions.tsx | 138 ++++++++++++++++++ .../components/challenge/student/Actions.tsx | 132 +++++++++++++++++ .../challenge/student/ChallStudentSection.tsx | 51 +++++++ .../{team => student_or_ce}/Actions.tsx | 7 +- .../student_or_ce/ChallStudentCeSection.tsx | 52 +++++++ .../challenge/team/ChallTeamSection.tsx | 4 +- .../components/challenge/team/TeamActions.tsx | 131 +++++++++++++++++ frontend/src/components/utils/Select.tsx | 53 ++++++- frontend/src/screens/Challenges.tsx | 21 ++- frontend/src/services/requests/challenges.ts | 29 +++- 17 files changed, 829 insertions(+), 39 deletions(-) create mode 100644 frontend/src/components/challenge/free/ChallFreeSection.tsx create mode 100644 frontend/src/components/challenge/free/FreeActions.tsx create mode 100644 frontend/src/components/challenge/student/Actions.tsx create mode 100644 frontend/src/components/challenge/student/ChallStudentSection.tsx rename frontend/src/components/challenge/{team => student_or_ce}/Actions.tsx (93%) create mode 100644 frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx create mode 100644 frontend/src/components/challenge/team/TeamActions.tsx diff --git a/backend/src/controllers/challenge.controller.ts b/backend/src/controllers/challenge.controller.ts index 4dee485c..9590c7de 100644 --- a/backend/src/controllers/challenge.controller.ts +++ b/backend/src/controllers/challenge.controller.ts @@ -20,10 +20,18 @@ export const getAllStudentOrCeChallenges = async (req: Request, res: Response, n } } +export const getAllFreeChallenges = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllFreeChallenges(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + export const validChallenge = async (req: Request, res: Response, next: NextFunction) => { try { const {challId, associatedId, attributedPoints, text} = req.body - console.log(req.body) const data = await service.validateChallenge(challId, associatedId, attributedPoints, text); Ok(res, { data }); } catch (error) { @@ -31,6 +39,27 @@ export const validChallenge = async (req: Request, res: Response, next: NextFunc } } +export const validFreeChallenge = async (req: Request, res: Response, next: NextFunction) => { + try { + const {associatedId, attributedPoints, text} = req.body + const data = await service.freeChallengeToFaction(associatedId, attributedPoints, text); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + +export const getAllFreeText = async (req: Request, res: Response, next: NextFunction) => { + try { + const {factionId} = req.body + const data = await service.getFreeChallenges(factionId); + const response = data.map(value => value.text) + Ok(res, {data: response}); + } catch (error) { + Error(res, { error }); + } +} + export const unvalidChallenge = async (req: Request, res: Response, next: NextFunction) => { try { const {challId, associatedId} = req.body @@ -41,6 +70,16 @@ export const unvalidChallenge = async (req: Request, res: Response, next: NextFu } } +export const unvalidFreeChallenge = async (req: Request, res: Response, next: NextFunction) => { + try { + const {factionId, text} = req.body + const data = await service.unvalidateToFaction(text, factionId); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + export const getAllStudentChallenges = async (req: Request, res: Response, next: NextFunction) => { try { const data = await service.getAllStudentChallenges(); diff --git a/backend/src/routes/challenge.routes.ts b/backend/src/routes/challenge.routes.ts index 80fbf805..937c9e01 100644 --- a/backend/src/routes/challenge.routes.ts +++ b/backend/src/routes/challenge.routes.ts @@ -7,10 +7,14 @@ const challengeRouter = express.Router(); challengeRouter.get('/countPoints', isAdminAnim, fc.countPoints); challengeRouter.get('/all', fc.getAllChallenges); challengeRouter.post('/valid', isAdminAnim, fc.validChallenge); +challengeRouter.post('/validFree', isAdminAnim, fc.validFreeChallenge); challengeRouter.post('/unvalid', isAdminAnim, fc.unvalidChallenge); +challengeRouter.post('/unvalidFree', isAdminAnim, fc.unvalidFreeChallenge); +challengeRouter.post('/allFreeText', isAdminAnim, fc.getAllFreeText) challengeRouter.get('/allFaction', fc.getAllFactionChallenges); challengeRouter.get('/allStudent', fc.getAllStudentChallenges); challengeRouter.get('/allTeam', fc.getAllTeamChallenges); challengeRouter.get('/allStudentOrCe', fc.getAllStudentOrCeChallenges); +challengeRouter.get('/allFree', fc.getAllFreeChallenges); export default challengeRouter; \ No newline at end of file diff --git a/backend/src/services/challenge.service.ts b/backend/src/services/challenge.service.ts index b16fa42b..9cb4ca74 100644 --- a/backend/src/services/challenge.service.ts +++ b/backend/src/services/challenge.service.ts @@ -7,12 +7,13 @@ import { } from "../schemas/challenge.schema" import {addPoints, removePoints} from "./faction.service" import { db } from "../database/db" -import {and, eq} from 'drizzle-orm' +import {and, eq, TableConfig} from 'drizzle-orm' import {PermType, userSchema} from "../schemas/user.schema"; import {teamSchema} from "../schemas/team.schema"; import {factionSchema} from "../schemas/faction.schema"; import assert from "node:assert"; import {getFactionFromUserId, getFactionFromUserTeam} from "../utils/challenge"; +import {PgTableWithColumns} from "drizzle-orm/pg-core"; export const getAllChallenges = async () => { @@ -55,6 +56,23 @@ export const getAllStudentChallenges = async () => { } } +export const getAllFreeChallenges = async () => { + try { + return await db.select().from(FreeToChallengeSchema) + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + +export const getFreeChallenges = async (factionId: number) => { + try { + return await db.select().from(FreeToChallengeSchema).where(eq(FreeToChallengeSchema.factionId, factionId)) + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + + export const getChallenge = async (id: number) => { try { const chall = await db.select().from(challengeSchema).where(eq(challengeSchema.id, id)) @@ -124,7 +142,6 @@ export const deleteChallenge = async (id: number) => { } export const validateChallenge = async (challengeId: number, associatedId: number, attributedPoints: number, text: string | null) => { - console.log("Cc") //First get the type of challenge const challenge = await db.select().from(challengeSchema).where(eq(challengeSchema.id, challengeId)); if(!challenge || challenge.length === 0) throw new Error("No challenge with id '" + challengeId + "'") @@ -150,8 +167,7 @@ export const validateChallenge = async (challengeId: number, associatedId: numbe } -//TODO -export const unvalidateChallenge = async (challengeId: number, associatedId: number) => { +export const unvalidateChallenge = async (challengeId: number, associatedId: number, text?: string) => { //First get the type of challenge const challenge = await db.select().from(challengeSchema).where(eq(challengeSchema.id, challengeId)); if(!challenge || challenge.length === 0) throw new Error("No challenge with id '" + challengeId + "'") @@ -170,7 +186,8 @@ export const unvalidateChallenge = async (challengeId: number, associatedId: num await unvalidateChallengeToFaction(challengeId, associatedId) break; case ChallengeType.Free: - await unvalidateToFaction(associatedId) + if(!text) throw new Error("You need to enter text.") + await unvalidateToFaction(text, associatedId) break; } } @@ -184,11 +201,93 @@ async function unvalidateChallengeToUser(challengeId: number, associatedId: numb eq(StudentTochallengeSchema.studentId, associatedId) ) ); - if(associatedChall.length === 0) throw new Error("Event already associated with this user. userId '" + associatedId + "'") + if(associatedChall.length === 0) throw new Error("Event not associated with this user. userId '" + associatedId + "'") const points = associatedChall[0].attributedPoints //Getting faction const faction = await getFactionFromUserId(associatedId) await removePoints(faction, points) + await db.delete(StudentTochallengeSchema) + .where( + and( + eq(StudentTochallengeSchema.challengeId, challengeId), + eq(StudentTochallengeSchema.studentId, associatedId) + ) + ); +} + +async function unvalidateChallengeToTeam(challengeId: number, associatedId: number) { + //Getting the challenge + const associatedChall = await db.select().from(TeamTochallengeSchema) + .where( + and( + eq(TeamTochallengeSchema.challengeId, challengeId), + eq(TeamTochallengeSchema.teamId, associatedId) + ) + ); + if(associatedChall.length === 0) throw new Error("Event not associated with this team. teamId '" + associatedId + "'") + const points = associatedChall[0].attributedPoints + + //Getting team + const team = await db.select().from(teamSchema).where(eq(teamSchema.id, associatedId)); + if(!team || team.length === 0) throw new Error("Team does not exist. id: " + associatedId); + await removePoints(team[0].faction as number, points) + await db.delete(TeamTochallengeSchema) + .where( + and( + eq(TeamTochallengeSchema.challengeId, challengeId), + eq(TeamTochallengeSchema.teamId, associatedId) + ) + ); +} + +async function unvalidateChallengeToFaction(challengeId: number, associatedId: number) { + //Getting the challenge + const associatedChall = await db.select().from(factionTochallengeSchema) + .where( + and( + eq(factionTochallengeSchema.challengeId, challengeId), + eq(factionTochallengeSchema.factionId, associatedId) + ) + ); + if(associatedChall.length === 0) throw new Error("Event not associated with this faction. factionId '" + associatedId + "'") + const points = associatedChall[0].attributedPoints + + //Getting team + const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, associatedId)); + if(!faction || faction.length === 0) throw new Error("Faction does not exist. id: " + associatedId); + await removePoints(faction[0].id as number, points) + await db.delete(factionTochallengeSchema) + .where( + and( + eq(factionTochallengeSchema.challengeId, challengeId), + eq(factionTochallengeSchema.factionId, associatedId) + ) + ); +} + +export async function unvalidateToFaction(text: string, associatedId: number) { + //Getting the challenge + const associatedChall = await db.select().from(FreeToChallengeSchema) + .where( + and( + eq(FreeToChallengeSchema.text, text), + eq(FreeToChallengeSchema.factionId, associatedId) + ) + ); + if(associatedChall.length === 0) throw new Error("Event not associated with this faction. factionId '" + associatedId + "'") + const points = associatedChall[0].attributedPoints + + //Getting team + const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, associatedId)); + if(!faction || faction.length === 0) throw new Error("Faction does not exist. id: " + associatedId); + await removePoints(faction[0].id as number, points) + await db.delete(FreeToChallengeSchema) + .where( + and( + eq(FreeToChallengeSchema.text, text), + eq(FreeToChallengeSchema.factionId, associatedId) + ) + ); } async function completeChallengeToUser(challengeId: number, associatedId: number, attributedPoints: number, allowCe: boolean) { @@ -211,16 +310,20 @@ async function completeChallengeToUser(challengeId: number, associatedId: number ); if(associatedChall && associatedChall.length > 0) throw new Error("Event already associated with this user. userId '" + associatedId + "'") - //associating the event - await db.insert(StudentTochallengeSchema).values({ - challengeId: challengeId, - studentId: associatedId, - attributedPoints: attributedPoints - }).execute(); //get associated faction - const faction = await getFactionFromUserTeam(user[0].team as number) - await addPoints(faction, attributedPoints) + try { + const faction = await getFactionFromUserTeam(user[0].team as number) + await addPoints(faction, attributedPoints) + //associating the event + await db.insert(StudentTochallengeSchema).values({ + challengeId: challengeId, + studentId: associatedId, + attributedPoints: attributedPoints + }).execute(); + } catch (error) { + throw error + } } async function completeChallengeToTeam(challengeId: number, associatedId: number, attributedPoints: number) { @@ -264,7 +367,6 @@ async function completeChallengeToFaction(challengeId: number, associatedId: num eq(factionTochallengeSchema.factionId, associatedId) ) ); - console.log(associatedChall) if(associatedChall && associatedChall.length > 0) throw new Error("Event already associated with this faction. teamId '" + associatedId + "'") //associating the event await db.insert(factionTochallengeSchema).values({ @@ -277,7 +379,7 @@ async function completeChallengeToFaction(challengeId: number, associatedId: num await addPoints(faction[0].id, attributedPoints) } -async function freeChallengeToFaction(factionId: number, attributedPoints: number, text: string) { +export async function freeChallengeToFaction(factionId: number, attributedPoints: number, text: string) { //means associatedId is a faction //checking faction exist const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, factionId)); diff --git a/backend/src/services/faction.service.ts b/backend/src/services/faction.service.ts index b8e9fa0d..c455a7c9 100644 --- a/backend/src/services/faction.service.ts +++ b/backend/src/services/faction.service.ts @@ -64,12 +64,15 @@ export const addPoints = async (id: number, points: number) => { } export const removePoints = async (id: number, points: number) => { + console.log("remove " + id + " " + points) const current_points = await getPoints(id); + console.log(current_points) try { await db.update(factionSchema) .set({ points: current_points - points }) .where(eq(factionSchema.id, id)); } catch (error) { + console.log(error) throw new Error("Failed to remove points. Please try again later."); } } \ No newline at end of file diff --git a/frontend/src/components/challenge/faction/Actions.tsx b/frontend/src/components/challenge/faction/Actions.tsx index 9908bf2f..5a56a7aa 100644 --- a/frontend/src/components/challenge/faction/Actions.tsx +++ b/frontend/src/components/challenge/faction/Actions.tsx @@ -12,7 +12,12 @@ import { ToastContainer, toast } from 'react-toastify'; import "react-toastify/dist/ReactToastify.css"; import {Challenge, ChallType} from "../../../services/interfaces"; import {toTable} from "../../utils/Tables"; -import {getChallenges, unvalidChallenge, validChallenge} from "../../../services/requests/challenges"; +import { + getChallenges, + unvalidChallenge, + unvalidFreeChallenge, + validChallenge +} from "../../../services/requests/challenges"; import {handleError, toId} from "../../utils/Submit"; import {changePermission} from "../../../services/requests/users"; import {Challenges, Factions, Users} from "../../utils/Select"; @@ -64,7 +69,10 @@ export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { /> setFaction(faction)} + value={faction} + /> + +
+
+
+ + setPoints(Number(e.target.value))} + /> +
+ + {/* Input pour le texte */} +
+ + setText(e.target.value)} + /> +
+
+ + + + ) +} + +export const UnvalidChallenge: React.FC = () => { + const [faction, setFaction] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + const [options, setOptions] = useState([]) + + const Submit = async () => { + await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidFreeChallenge, faction.value, challenge.value) + setFaction({}) + setChallenge({}) + } + + useEffect(() => { + getFreeChallengeText(faction.value) + .then(value => { + setOptions(value)}) + }, [faction]); + + return ( +
+
+ setChallenge(chall)} + value={challenge} + /> + +
+ + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/challenge/student/Actions.tsx b/frontend/src/components/challenge/student/Actions.tsx new file mode 100644 index 00000000..38507aa6 --- /dev/null +++ b/frontend/src/components/challenge/student/Actions.tsx @@ -0,0 +1,132 @@ +import React, { useEffect, useState } from 'react'; +import Select from 'react-select' +import { + createTeam, + addToFaction, + deleteTeam, + getAllTeams, + renameTeam, + validateTeam, +} from '../../../services/requests/teams'; +import { ToastContainer, toast } from 'react-toastify'; +import "react-toastify/dist/ReactToastify.css"; +import {Challenge, ChallType} from "../../../services/interfaces"; +import {toTable} from "../../utils/Tables"; +import {getChallenges, unvalidChallenge, validChallenge} from "../../../services/requests/challenges"; +import {handleError, toId} from "../../utils/Submit"; +import {changePermission} from "../../../services/requests/users"; +import {Challenges, Factions, Users} from "../../utils/Select"; + +interface TableChallengeType { + type: ChallType +} + +export const TableChallenge: React.FC = ({ type }) => { + + const [challenges, setChallenges] = useState([]); + + useEffect(() => { + const fetchChallenges = async () => { + try { + const teams = await getChallenges(type); + setChallenges(teams) + } catch (error) { + console.error('Error fetching challenges:', error); + } + }; + fetchChallenges(); + }, []); + return challenges.length > 0 ? toTable(challenges) : null; +} + +export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [faction, setFaction] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + const [points, setPoints] = useState(0) + const [text, setText] = useState("") + + const Submit = async () => { + const id = toId(faction) + await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) + setFaction({}) + setChallenge({}) + setPoints(0) + setText("") + } + + return ( +
+
+ { + setText(chall.description + " : " + chall.points) + setChallenge(chall) + }} + value={challenge} + /> + +
+
+
+ + setPoints(Number(e.target.value))} + /> +
+ + {/* Input pour le texte */} +
+ + setText(e.target.value)} + /> +
+
+ + +
+ ) +} + +export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [student, setUsers] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + + const Submit = async () => { + await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidChallenge, challenge.value, student.value) + setUsers({}) + setChallenge({}) + } + + return ( +
+
+ setChallenge(chall)} + value={challenge} + /> + +
+ + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/challenge/student/ChallStudentSection.tsx b/frontend/src/components/challenge/student/ChallStudentSection.tsx new file mode 100644 index 00000000..d71338ff --- /dev/null +++ b/frontend/src/components/challenge/student/ChallStudentSection.tsx @@ -0,0 +1,51 @@ +import React, {useEffect, useState} from 'react'; +import {TableChallenge, UnvalidChallenge, ValidChallenge} from './Actions'; +import {getRole} from '../../../services/requests'; +import AnimSection from "../AnimSection"; +import {AdminAction} from "../../admin/AdminSection"; +import {ChallType} from "../../../services/interfaces"; + + +const ChallStudentSection: React.FC = () => { + + const [clicked, setClicked] = useState(false); + const [role, setRole] = useState(null); + + const handleClick = () => { + setClicked(!clicked); + } + + useEffect(() => { + const fetchRole = async () => { + try { + const role = await getRole(); + setRole(role); + } catch (error) { + console.error('Error fetching role:', error); + } + }; + + fetchRole(); + }, []); + + const actions: AdminAction[] = [ + { + title: 'Valider challenge', + form: , + }, + { + title: 'Unvalider challenge', + form: , + }, + { + title: 'Affichage challenges', + form: , + } + ]; + + return ( + + ); +}; + +export default ChallStudentSection; diff --git a/frontend/src/components/challenge/team/Actions.tsx b/frontend/src/components/challenge/student_or_ce/Actions.tsx similarity index 93% rename from frontend/src/components/challenge/team/Actions.tsx rename to frontend/src/components/challenge/student_or_ce/Actions.tsx index ffadf8dd..43e611ed 100644 --- a/frontend/src/components/challenge/team/Actions.tsx +++ b/frontend/src/components/challenge/student_or_ce/Actions.tsx @@ -58,13 +58,16 @@ export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => {
setChallenge(chall)} + onChange={chall => { + setText(chall.description + " : " + chall.points) + setChallenge(chall) + }} value={challenge} /> diff --git a/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx b/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx new file mode 100644 index 00000000..d6d61979 --- /dev/null +++ b/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx @@ -0,0 +1,52 @@ +import React, {useEffect, useState} from 'react'; +import {TableChallenge, ValidChallenge} from './Actions'; +import {getRole} from '../../../services/requests'; +import AnimSection from "../AnimSection"; +import {AdminAction} from "../../admin/AdminSection"; +import {ChallType} from "../../../services/interfaces"; +import {UnvalidChallenge} from "../student/Actions"; + + +const ChallStudentCeSection: React.FC = () => { + + const [clicked, setClicked] = useState(false); + const [role, setRole] = useState(null); + + const handleClick = () => { + setClicked(!clicked); + } + + useEffect(() => { + const fetchRole = async () => { + try { + const role = await getRole(); + setRole(role); + } catch (error) { + console.error('Error fetching role:', error); + } + }; + + fetchRole(); + }, []); + + const actions: AdminAction[] = [ + { + title: 'Valider challenge', + form: , + }, + { + title: 'Unvalider challenge', + form: , + }, + { + title: 'Affichage challenges', + form: , + } + ]; + + return ( + + ); +}; + +export default ChallStudentCeSection; diff --git a/frontend/src/components/challenge/team/ChallTeamSection.tsx b/frontend/src/components/challenge/team/ChallTeamSection.tsx index 24aa4b09..7bb5c689 100644 --- a/frontend/src/components/challenge/team/ChallTeamSection.tsx +++ b/frontend/src/components/challenge/team/ChallTeamSection.tsx @@ -1,5 +1,5 @@ import React, {useEffect, useState} from 'react'; -import {TableChallenge, ValidChallenge} from './Actions'; +import {TableChallenge, UnvalidChallenge, ValidChallenge} from './TeamActions'; import {getRole} from '../../../services/requests'; import AnimSection from "../AnimSection"; import {AdminAction} from "../../admin/AdminSection"; @@ -34,7 +34,7 @@ const ChallTeamSection: React.FC = () => { }, { title: 'Unvalider challenge', - form: , + form: , }, { title: 'Affichage challenges', diff --git a/frontend/src/components/challenge/team/TeamActions.tsx b/frontend/src/components/challenge/team/TeamActions.tsx new file mode 100644 index 00000000..c9daddcc --- /dev/null +++ b/frontend/src/components/challenge/team/TeamActions.tsx @@ -0,0 +1,131 @@ +import React, { useEffect, useState } from 'react'; +import Select from 'react-select' +import { + createTeam, + addToFaction, + deleteTeam, + getAllTeams, + renameTeam, + validateTeam, +} from '../../../services/requests/teams'; +import { ToastContainer, toast } from 'react-toastify'; +import "react-toastify/dist/ReactToastify.css"; +import {Challenge, ChallType} from "../../../services/interfaces"; +import {toTable} from "../../utils/Tables"; +import {getChallenges, unvalidChallenge, validChallenge} from "../../../services/requests/challenges"; +import {handleError, toId} from "../../utils/Submit"; +import {changePermission} from "../../../services/requests/users"; +import {Challenges, Factions, Teams, Users} from "../../utils/Select"; + +interface TableChallengeType { + type: ChallType +} + +export const TableChallenge: React.FC = ({ type }) => { + + const [challenges, setChallenges] = useState([]); + + useEffect(() => { + const fetchChallenges = async () => { + try { + const teams = await getChallenges(type); + setChallenges(teams) + } catch (error) { + console.error('Error fetching challenges:', error); + } + }; + fetchChallenges(); + }, []); + return challenges.length > 0 ? toTable(challenges) : null; +} + +export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [faction, setFaction] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + const [points, setPoints] = useState(0) + const [text, setText] = useState("") + + const Submit = async () => { + const id = toId(faction) + await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) + setFaction({}) + setChallenge({}) + setPoints(0) + setText("") + } + + return ( +
+
+ { + setText(chall.description + " : " + chall.points) + setChallenge(chall) + }} + value={challenge} + /> + +
+
+
+ + setPoints(Number(e.target.value))} + /> +
+ + {/* Input pour le texte */} +
+ + setText(e.target.value)} + /> +
+
+ + +
+ ) +} +export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => { + const [team, setTeam] = useState({} as any) + const [challenge, setChallenge] = useState({} as any) + + const Submit = async () => { + await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidChallenge, challenge.value, team.value) + setTeam({}) + setChallenge({}) + } + + return ( +
+
+ setChallenge(chall)} + value={challenge} + /> + +
+ + +
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/utils/Select.tsx b/frontend/src/components/utils/Select.tsx index f0875a43..1216b9c9 100644 --- a/frontend/src/components/utils/Select.tsx +++ b/frontend/src/components/utils/Select.tsx @@ -6,7 +6,7 @@ import { getActiveEvents, getInactiveEvents } from "../../services/requests/even import { getAllUUID } from "../../services/requests/newstudent" import { getAllPerms } from "../../services/requests/perms" import { getAllByPermission } from "../../services/requests/users" -import {getAllChallenges, getChallenges} from "../../services/requests/challenges"; +import {getAllChallenges, getAllFreeChallengesTexts, getChallenges} from "../../services/requests/challenges"; export const Roles = () => { const [options, setOptions] = useState([]) @@ -109,13 +109,61 @@ export const Challenges = (challType: ChallType) => { try { const response = await getChallenges(challType) const challOptions = response.map((chall: Challenge) => { + return { + value: chall.id, + label: chall.name, + description: chall.description, + points: chall.points + } + }) + setOptions(challOptions) + } catch (error) { + console.error('Error fetching data:', error) + } + } + + fetchData() + }, []) + + return options +} + +export const getFreeChallengeText = async (factionId: number): Promise<{value: string, label: string}[]> => { + + return await getAllFreeChallengesTexts(factionId) + .then(data => { + if(!data || data.length === 0) return [] + const response = data.map((chall: Challenge) => { + if(!chall) return {value: "", label: "undefined"} console.log(chall) + return { + value: chall, + label: chall, + } + }) + return response + }) + .catch(error => { + console.log(error) + }) + +} + +export const ValidedChallenge = (challType: ChallType) => { + const [options, setOptions] = useState([]) + + useEffect(() => { + const fetchData = async () => { + try { + const response = await getChallenges(challType) + const challOptions = response.map((chall: Challenge) => { return { value: chall.id, label: chall.name, + description: chall.description, + points: chall.points } }) - console.log(challOptions) setOptions(challOptions) } catch (error) { console.error('Error fetching data:', error) @@ -128,6 +176,7 @@ export const Challenges = (challType: ChallType) => { return options } + export const Users = () => { const [options, setOptions] = useState([]) diff --git a/frontend/src/screens/Challenges.tsx b/frontend/src/screens/Challenges.tsx index 9f9a99de..9fd4e472 100644 --- a/frontend/src/screens/Challenges.tsx +++ b/frontend/src/screens/Challenges.tsx @@ -1,12 +1,13 @@ -import { Navbar } from "../components/shared/Navbar" +import {Navbar} from "../components/shared/Navbar" import {useEffect, useState} from "react"; -import { Section } from "../components/shared/Section"; -import { Default } from "../components/shared/Default"; -import { getCurrentUser } from "../services/requests/users"; -import UserAdminSection from "../components/admin/users/UserAdminSection"; -import AnimSection from "../components/challenge/AnimSection"; +import {Section} from "../components/shared/Section"; +import {getCurrentUser} from "../services/requests/users"; import ChallFactionSection from "../components/challenge/faction/ChallFactionSection"; import ChallTeamSection from "../components/challenge/team/ChallTeamSection"; +import ChallStudentSection from "../components/challenge/student/ChallStudentSection"; +import {ChallType} from "../services/interfaces"; +import ChallStudentCeSection from "../components/challenge/student_or_ce/ChallStudentCeSection"; +import ChallFreeSection from "../components/challenge/free/ChallFreeSection"; export const Defis = () => { const [permission, setPermission] = useState(null); @@ -32,17 +33,21 @@ export const Defis = () => { fetchUser(); }, []); + //TODO: factoriser. j'ai essayé vite fait mais ça fait longtemps j'ai pas fait de react mdr return (
+
+
+
) } /* -
-
+
+
*/ \ No newline at end of file diff --git a/frontend/src/services/requests/challenges.ts b/frontend/src/services/requests/challenges.ts index 07ab4efe..4335ff2c 100644 --- a/frontend/src/services/requests/challenges.ts +++ b/frontend/src/services/requests/challenges.ts @@ -12,7 +12,15 @@ export const getChallenges = async (type: ChallType) => { return response.data.data; }; +export const getAllFreeChallengesTexts = async (factionId: number) => { + const response = await api.post("challenge/allFreeText", { + factionId + }); + return response.data.data; +}; + export const validChallenge = async (associatedId: number, challId: number, attributedPoints: number, text: string|null) => { + console.log("ratio") return await api.post('challenge/valid', { associatedId, challId, @@ -21,9 +29,24 @@ export const validChallenge = async (associatedId: number, challId: number, attr }) } -export const unvalidChallenge = async (associatedId: number, challId: number) => { - return await api.post('challenge/unvalid', { +export const validFreeChallenge = async (associatedId: number, attributedPoints: number, text: string|null) => { + return await api.post('challenge/validFree', { associatedId, - challId + attributedPoints, + text + }) +} + +export const unvalidFreeChallenge = async (factionId: number, text: number) => { + return await api.post('challenge/unvalidFree', { + factionId, + text + }) +} + +export const unvalidChallenge = async (challId: number, associatedId: number) => { + return await api.post('challenge/unvalid', { + challId, + associatedId }) } From 6d3e3ca55b92bfaa54e04b4a9abbcd716a3dcd43 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 11:12:45 +0200 Subject: [PATCH 09/15] Remove drizzle folder --- backend/drizzle/meta/_journal.json | 20 -------------------- backend/drizzle/migration/migrate.ts | 24 ------------------------ 2 files changed, 44 deletions(-) delete mode 100644 backend/drizzle/meta/_journal.json delete mode 100644 backend/drizzle/migration/migrate.ts diff --git a/backend/drizzle/meta/_journal.json b/backend/drizzle/meta/_journal.json deleted file mode 100644 index c7c3250b..00000000 --- a/backend/drizzle/meta/_journal.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": "5", - "dialect": "pg", - "entries": [ - { - "idx": 0, - "version": "5", - "when": 1723458432056, - "tag": "0000_wealthy_hellfire_club", - "breakpoints": true - }, - { - "idx": 1, - "version": "5", - "when": 1723472551183, - "tag": "0001_robust_iron_patriot", - "breakpoints": true - } - ] -} \ No newline at end of file diff --git a/backend/drizzle/migration/migrate.ts b/backend/drizzle/migration/migrate.ts deleted file mode 100644 index de5cc220..00000000 --- a/backend/drizzle/migration/migrate.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Pool } from "pg"; -import { drizzle } from "drizzle-orm/node-postgres"; -import { migrate } from "drizzle-orm/node-postgres/migrator"; -import dotenv from "dotenv"; - -dotenv.config() - -const pool = new Pool({ - connectionString: process.env.OUTSIDE_DATABASE_URL, -}); - - -const db = drizzle(pool); - -export async function main() { - await migrate(db, { migrationsFolder: "drizzle" }); - pool.end(); - process.exit(0); -} - -main().catch((err) => { - console.log(err); - process.exit(0); -}); \ No newline at end of file From 7c5137a0a82676bb3aab2bfa7b113c68eea6ebb7 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 11:14:10 +0200 Subject: [PATCH 10/15] Remove files --- backend/.env | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 backend/.env diff --git a/backend/.env b/backend/.env deleted file mode 100644 index ccd4ecc5..00000000 --- a/backend/.env +++ /dev/null @@ -1,7 +0,0 @@ -DATABASE_URL="postgresql://admin:password@postgres:5432/db" -OUTSIDE_DATABASE_URL="postgresql://admin:password@localhost:5432/db" -API_PREFIX=/api - -JWT_SECRET="SecretKey" -ETU_UTT_CLIENT_ID="15906313225" -ETU_UTT_CLIENT_SECRET="253cca3d8c575e5796feff25df261056" \ No newline at end of file From e43c0a8179f6f38953d4eed763c7ce6bad7122ce Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 13:41:56 +0200 Subject: [PATCH 11/15] Proper CE separation. Auto complete for validate and unvalidate --- .../src/controllers/challenge.controller.ts | 118 +++++++++++-- backend/src/controllers/team.controller.ts | 9 + backend/src/controllers/user.controller.ts | 19 +++ backend/src/error/user.ts | 5 + backend/src/routes/challenge.routes.ts | 19 ++- backend/src/routes/team.routes.ts | 1 + backend/src/routes/user.routes.ts | 2 + backend/src/services/challenge.service.ts | 155 +++++++++++++++--- backend/src/services/team.service.ts | 16 ++ backend/src/services/user.service.ts | 109 +++++++++++- backend/src/utils/challenge.ts | 64 +++++++- .../src/components/admin/users/Actions.tsx | 54 ++++++ .../admin/users/UserAdminSection.tsx | 7 +- .../{student/Actions.tsx => AnimAction.tsx} | 64 ++++---- .../{AnimSection.tsx => BaseAnimSection.tsx} | 4 +- .../components/challenge/faction/Actions.tsx | 137 ---------------- .../challenge/faction/ChallFactionSection.tsx | 6 +- .../challenge/free/ChallFreeSection.tsx | 4 +- .../components/challenge/free/FreeActions.tsx | 24 +-- .../challenge/student/ChallStudentSection.tsx | 6 +- .../challenge/student_or_ce/Actions.tsx | 101 ------------ .../student_or_ce/ChallStudentCeSection.tsx | 7 +- .../challenge/team/ChallTeamSection.tsx | 6 +- .../components/challenge/team/TeamActions.tsx | 131 --------------- .../components/factions/FactionsAffichage.tsx | 16 +- frontend/src/components/utils/Select.tsx | 41 ++--- frontend/src/services/requests.ts | 7 + frontend/src/services/requests/challenges.ts | 9 +- frontend/src/services/requests/teams.ts | 5 + 29 files changed, 630 insertions(+), 516 deletions(-) create mode 100644 backend/src/error/user.ts rename frontend/src/components/challenge/{student/Actions.tsx => AnimAction.tsx} (63%) rename frontend/src/components/challenge/{AnimSection.tsx => BaseAnimSection.tsx} (90%) delete mode 100644 frontend/src/components/challenge/faction/Actions.tsx delete mode 100644 frontend/src/components/challenge/student_or_ce/Actions.tsx delete mode 100644 frontend/src/components/challenge/team/TeamActions.tsx diff --git a/backend/src/controllers/challenge.controller.ts b/backend/src/controllers/challenge.controller.ts index 9590c7de..4124d51f 100644 --- a/backend/src/controllers/challenge.controller.ts +++ b/backend/src/controllers/challenge.controller.ts @@ -1,20 +1,28 @@ import { Request, Response, NextFunction } from 'express'; import * as service from '../services/challenge.service'; import { Error, Created, Ok } from '../utils/responses'; +import {getAllChallenges, getChallengeFromIds} from "../utils/challenge"; +import {NoUser} from "../error/user"; +import {getCompletedChallengesForCe, getCompletedChallengesForFaction} from "../services/challenge.service"; -export const getAllChallenges = async (req: Request, res: Response, next: NextFunction) => { +export const getAllChallengesInDb = async (req: Request, res: Response, next: NextFunction) => { try { - const data = await service.getAllChallenges(); + const data = await getAllChallenges(); Ok(res, { data }); } catch (error) { Error(res, { error }); } } -export const getAllStudentOrCeChallenges = async (req: Request, res: Response, next: NextFunction) => { +export const getAllCeChallenges = async (req: Request, res: Response, next: NextFunction) => { try { - const data = await service.getAllStudentOrCeChallenges(); - Ok(res, { data }); + const {filter, associatedId} = req.body + switch (filter) { + case "available": return Ok(res, { data: await service.getAvailableChallengeForCe(associatedId) } ) + case "completed": return Ok(res, { data: await getChallengeFromIds(await service.getCompletedChallengesForStudent(associatedId)) } ) + case "all": return Ok(res, { data: await service.getAllCeChallenges() } ) + default: Error(res, {msg: "filter '" + filter + "' do not exist."}) + } } catch (error) { Error(res, { error }); } @@ -82,8 +90,13 @@ export const unvalidFreeChallenge = async (req: Request, res: Response, next: Ne export const getAllStudentChallenges = async (req: Request, res: Response, next: NextFunction) => { try { - const data = await service.getAllStudentChallenges(); - Ok(res, { data }); + const {filter, associatedId} = req.body + switch (filter) { + case "available": return Ok(res, { data: await service.getAvailableChallengeForStudent(associatedId) } ) + case "completed": return Ok(res, { data: await getChallengeFromIds(await service.getCompletedChallengesForStudent(associatedId)) } ) + case "all": return Ok(res, { data: await service.getAllStudentChallenges() } ) + default: Error(res, {msg: "filter '" + filter + "' do not exist."}) + } } catch (error) { Error(res, { error }); } @@ -91,8 +104,14 @@ export const getAllStudentChallenges = async (req: Request, res: Response, next: export const getAllFactionChallenges = async (req: Request, res: Response, next: NextFunction) => { try { - const data = await service.getAllFactionChallenges(); - Ok(res, { data }); + const {filter, associatedId} = req.body + console.log("filter: " + filter + " id: " + associatedId) + switch (filter) { + case "available": return Ok(res, { data: await service.getAvailableChallengeForFaction(associatedId) } ) + case "completed": return Ok(res, { data: await getChallengeFromIds(await service.getCompletedChallengesForFaction(associatedId)) } ) + case "all": return Ok(res, { data: await service.getAllFactionChallenges() } ) + default: Error(res, {msg: "filter '" + filter + "' do not exist."}) + } } catch (error) { Error(res, { error }); } @@ -100,8 +119,13 @@ export const getAllFactionChallenges = async (req: Request, res: Response, next: export const getAllTeamChallenges = async (req: Request, res: Response, next: NextFunction) => { try { - const data = await service.getAllTeamChallenges(); - Ok(res, { data }); + const {filter, associatedId} = req.body + switch (filter) { + case "available": return Ok(res, { data: await service.getAvailableChallengeForTeam(associatedId) } ) + case "completed": return Ok(res, { data: await getChallengeFromIds(await service.getCompletedChallengesForTeam(associatedId)) } ) + case "all": return Ok(res, { data: await service.getAllTeamChallenges() } ) + default: Error(res, {msg: "filter '" + filter + "' do not exist."}) + } } catch (error) { Error(res, { error }); } @@ -144,6 +168,78 @@ export const validateChallenge = async (req: Request, res: Response, next: NextF } } +export const getAvailableChallengeForTeam = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + try { + const data = await service.getAvailableChallengeForTeam(associatedId); + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + +export const getAvailableChallengeForFaction = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + try { + const data = await service.getAvailableChallengeForFaction(associatedId); + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + +export const getAvailableChallengeForStudent = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + try { + const data = await service.getAvailableChallengeForStudent(associatedId); + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + +export const getCompletedChallengeForTeam = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + try { + const data = await getChallengeFromIds(await service.getCompletedChallengesForTeam(associatedId)); + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + +export const getCompletedChallengeForFaction = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + console.log("yoooo") + try { + const data = await getChallengeFromIds(await service.getCompletedChallengesForFaction(associatedId)); + console.log(data) + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + +export const getCompletedChallengeForStudent = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + try { + const data = await getChallengeFromIds(await service.getCompletedChallengesForStudent(associatedId)); + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + +export const countPointsForTeam = async (req: Request, res: Response, next: NextFunction) => { + const { associatedId } = req.body; + try { + const data = await service.countPointsForTeam(associatedId); + Ok(res, { data: data, msg: "OK" }); + } catch (error) { + Error(res, { error }); + } +} + export const countPoints = async (req: Request, res: Response, next: NextFunction) => { try { diff --git a/backend/src/controllers/team.controller.ts b/backend/src/controllers/team.controller.ts index 22afc21f..21e000a9 100644 --- a/backend/src/controllers/team.controller.ts +++ b/backend/src/controllers/team.controller.ts @@ -14,6 +14,15 @@ export const getAllTeams = async (req: Request, res: Response, next: NextFunctio } } +export const getAllTeamsWithPoints = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllTeamsWithPoints(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + export const getTeam = async (req: Request, res: Response, next: NextFunction) => { const { id } = req.params; const idNumber = parseInt(id, 10); diff --git a/backend/src/controllers/user.controller.ts b/backend/src/controllers/user.controller.ts index 44798d26..e88c3297 100644 --- a/backend/src/controllers/user.controller.ts +++ b/backend/src/controllers/user.controller.ts @@ -13,6 +13,15 @@ export const getAllUsers = async (req: Request, res: Response, next: NextFunctio } } +export const getAllCe = async (req: Request, res: Response, next: NextFunction) => { + try { + const data = await service.getAllCe(); + Ok(res, { data }); + } catch (error) { + Error(res, { error }); + } +} + export const getAllByPermission= async (req: Request, res: Response, next: NextFunction) => { const {permission} = req.params; @@ -127,6 +136,16 @@ export const addContact = async (req: Request, res: Response, next: NextFunction } }; +export const getInfo = async (req: Request, res: Response, next: NextFunction) => { + const { email } = req.body + try { + const data = await service.getInfo(email) + Ok(res, {data: data, msg: "Ok"}) + } catch (error) { + Error(res, { error }) + } +} + export const changePermission = async (req: Request, res: Response, next: NextFunction) => { const { id, perm } = req.body; diff --git a/backend/src/error/user.ts b/backend/src/error/user.ts new file mode 100644 index 00000000..72bb17b5 --- /dev/null +++ b/backend/src/error/user.ts @@ -0,0 +1,5 @@ + + +export const NoUser = (id: number) => new Error("No user with id '" + id + "'") +export const NoTeam = (id: number | null) => new Error("No team with id '" + id + "'") +export const NoFaction = (id: number) => new Error("No faction with id '" + id + "'") \ No newline at end of file diff --git a/backend/src/routes/challenge.routes.ts b/backend/src/routes/challenge.routes.ts index 937c9e01..ae940dbb 100644 --- a/backend/src/routes/challenge.routes.ts +++ b/backend/src/routes/challenge.routes.ts @@ -5,16 +5,23 @@ import {isAdmin, isAdminAnim, isAdminCE} from '../middlewares/permissions'; const challengeRouter = express.Router(); challengeRouter.get('/countPoints', isAdminAnim, fc.countPoints); -challengeRouter.get('/all', fc.getAllChallenges); +challengeRouter.get('/countPointsForTeam', isAdminAnim, fc.countPointsForTeam); +challengeRouter.get('/all', fc.getAllChallengesInDb); challengeRouter.post('/valid', isAdminAnim, fc.validChallenge); challengeRouter.post('/validFree', isAdminAnim, fc.validFreeChallenge); +challengeRouter.post('/getCompletedForTeam', isAdminAnim, fc.getCompletedChallengeForTeam); +challengeRouter.post('/getCompletedForFaction', isAdminAnim, fc.getCompletedChallengeForFaction); +challengeRouter.post('/getCompletedForStudent', isAdminAnim, fc.getCompletedChallengeForStudent); +challengeRouter.post('/getAvailableForTeam', isAdminAnim, fc.getAvailableChallengeForTeam); +challengeRouter.post('/getAvailableForStudent', isAdminAnim, fc.getAvailableChallengeForStudent); +challengeRouter.post('/getAvailableForFaction', isAdminAnim, fc.getAvailableChallengeForFaction); challengeRouter.post('/unvalid', isAdminAnim, fc.unvalidChallenge); challengeRouter.post('/unvalidFree', isAdminAnim, fc.unvalidFreeChallenge); challengeRouter.post('/allFreeText', isAdminAnim, fc.getAllFreeText) -challengeRouter.get('/allFaction', fc.getAllFactionChallenges); -challengeRouter.get('/allStudent', fc.getAllStudentChallenges); -challengeRouter.get('/allTeam', fc.getAllTeamChallenges); -challengeRouter.get('/allStudentOrCe', fc.getAllStudentOrCeChallenges); -challengeRouter.get('/allFree', fc.getAllFreeChallenges); +challengeRouter.post('/allFaction', fc.getAllFactionChallenges); +challengeRouter.post('/allStudent', fc.getAllStudentChallenges); +challengeRouter.post('/allTeam', fc.getAllTeamChallenges); +challengeRouter.post('/allStudentOrCe', fc.getAllCeChallenges); +challengeRouter.post('/allFree', fc.getAllFreeChallenges); export default challengeRouter; \ No newline at end of file diff --git a/backend/src/routes/team.routes.ts b/backend/src/routes/team.routes.ts index 5e54fc99..caefbc4b 100644 --- a/backend/src/routes/team.routes.ts +++ b/backend/src/routes/team.routes.ts @@ -7,6 +7,7 @@ const teamRouter = express.Router(); teamRouter.post('/register', tc.registerTeam); teamRouter.post('', isAdminCE, tc.createTeam); teamRouter.get('/all', tc.getAllTeams); +teamRouter.get('/allWithPoints', tc.getAllTeamsWithPoints); teamRouter.get('/:id', isAdminCE, tc.getTeam); teamRouter.delete('/:id', isAdminCE, tc.deleteTeam); teamRouter.put('/addtofaction', isAdminCE, tc.addToFaction); diff --git a/backend/src/routes/user.routes.ts b/backend/src/routes/user.routes.ts index 53497de4..320a7405 100644 --- a/backend/src/routes/user.routes.ts +++ b/backend/src/routes/user.routes.ts @@ -5,6 +5,7 @@ import { isAdmin, isAdminCE } from '../middlewares/permissions'; const userRouter = express.Router(); userRouter.get('/all', isAdminCE, sc.getAllUsers); +userRouter.get('/ce/all', isAdminCE, sc.getAllCe); userRouter.get('/user/:id', isAdminCE, sc.getUser); userRouter.delete('/delete/:id', isAdmin, sc.deleteUser); userRouter.put('/addtoteam', isAdminCE, sc.addToTeam); @@ -16,6 +17,7 @@ userRouter.get('/all/light', sc.getUserLight); userRouter.get('/getbyteam/:teamId',isAdmin ,sc.getUserbyTeam); userRouter.post('/modifyteam', isAdmin, sc.modifyTeam); userRouter.get('/allbypermission/:permission', isAdmin, sc.getAllByPermission); +userRouter.post('/getInfo', isAdmin, sc.getInfo); export default userRouter; \ No newline at end of file diff --git a/backend/src/services/challenge.service.ts b/backend/src/services/challenge.service.ts index 9cb4ca74..89687655 100644 --- a/backend/src/services/challenge.service.ts +++ b/backend/src/services/challenge.service.ts @@ -1,28 +1,27 @@ import { - challengeSchema, challenge, + challengeSchema, + ChallengeType, factionTochallengeSchema, - factionTochallenge, - ChallengeType, StudentTochallengeSchema, TeamTochallengeSchema, freeToChallenge, FreeToChallengeSchema + FreeToChallengeSchema, + StudentTochallengeSchema, + TeamTochallengeSchema } from "../schemas/challenge.schema" import {addPoints, removePoints} from "./faction.service" -import { db } from "../database/db" -import {and, eq, TableConfig} from 'drizzle-orm' +import {db} from "../database/db" +import {and, eq} from 'drizzle-orm' import {PermType, userSchema} from "../schemas/user.schema"; import {teamSchema} from "../schemas/team.schema"; import {factionSchema} from "../schemas/faction.schema"; -import assert from "node:assert"; -import {getFactionFromUserId, getFactionFromUserTeam} from "../utils/challenge"; -import {PgTableWithColumns} from "drizzle-orm/pg-core"; - - -export const getAllChallenges = async () => { - try { - return await db.select().from(challengeSchema); - } catch (error) { - throw new Error("Failed to fetch challenges. Please try again later."); - } -} +import { + getAllChallenges, + getAllChallengesExcept, + getChallengeFromIds, getChallengesOf, + getFactionFromTeam, + getFactionFromUserId, + getTeamAndFactionFromUserId +} from "../utils/challenge"; +import {NoFaction} from "../error/user"; export const getAllFactionChallenges = async () => { try { @@ -56,6 +55,14 @@ export const getAllStudentChallenges = async () => { } } +export const getAllCeChallenges = async () => { + try { + return await db.select().from(challengeSchema).where(eq(challengeSchema.challType, ChallengeType.StudentOrCe)); + } catch (error) { + throw new Error("Failed to fetch challenges. Please try again later."); + } +} + export const getAllFreeChallenges = async () => { try { return await db.select().from(FreeToChallengeSchema) @@ -91,13 +98,100 @@ export const getFactionChallenges = async (factionId: number) => { } } +export const getCompletedChallengesForFaction = async (factionId: number): Promise => { + const factionChallenges = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema.factionId, factionId)) + return factionChallenges.map(chall => chall.challengeId) +} + +export const getCompletedChallengesForTeam = async (teamId: number): Promise => { + const factionId = await getFactionFromTeam(teamId) + const teamChallenges = await db.select().from(TeamTochallengeSchema).where(eq(TeamTochallengeSchema.teamId, teamId)) + const teamChallengeIds = teamChallenges.map(chall => chall.challengeId); + const factionChallenges = await getCompletedChallengesForFaction(factionId) + return [...factionChallenges, ...teamChallengeIds] +} + +export const getCompletedChallengesForStudent = async (studentId: number): Promise => { + const ids = await getTeamAndFactionFromUserId(studentId) + //get regular studentToChallenge + const studentChallenges = await db.select().from(StudentTochallengeSchema).where(eq(StudentTochallengeSchema.studentId, studentId)) + const studentChallengesIds = studentChallenges.map(chall => chall.challengeId) + const teamChallenges = await getCompletedChallengesForTeam(ids.teamId) + const factionChallenges = await getCompletedChallengesForFaction(ids.factionId) + return [...studentChallengesIds, ...teamChallenges, ...factionChallenges] +} + +export const getCompletedChallengesForCe = async (studentId: number): Promise => { + const ids = await getTeamAndFactionFromUserId(studentId) + //get regular studentToChallenge + const studentChallenges = await db.select().from(StudentTochallengeSchema).where(eq(StudentTochallengeSchema.studentId, studentId)) + const studentChallengesIds = studentChallenges.map(chall => chall.challengeId) + const teamChallenges = await getCompletedChallengesForTeam(ids.teamId) + const factionChallenges = await getCompletedChallengesForFaction(ids.factionId) + return [...studentChallengesIds, ...teamChallenges, ...factionChallenges] +} + +export const getAvailableChallengeForStudent = async (studentId: number): Promise => { + const ids = await getTeamAndFactionFromUserId(studentId) + const completedChallengesIds = + [ + ...await getCompletedChallengesForStudent(studentId), + ...await getCompletedChallengesForTeam(ids.teamId), + ...await getCompletedChallengesForFaction(ids.factionId) + ] + const allChallenges = await getAllChallenges() + const allChallengesIds = allChallenges.map(chall => chall.id as number) + const availableChallengeIds = allChallengesIds.filter(id => !completedChallengesIds.includes(id)); + return getChallengeFromIds(availableChallengeIds) +} + +export const getAvailableChallengeForCe = async (studentId: number): Promise => { + const ids = await getTeamAndFactionFromUserId(studentId) + const completedChallengesIds = + [ + ...await getCompletedChallengesForCe(studentId), + ...await getCompletedChallengesForTeam(ids.teamId), + ...await getCompletedChallengesForFaction(ids.factionId) + ] + const allChallenges = await getAllCeChallenges() + const allChallengesIds = allChallenges.map(chall => chall.id as number) + const availableChallengeIds = allChallengesIds.filter(id => !completedChallengesIds.includes(id)); + return getChallengeFromIds(availableChallengeIds) +} + +export const getAvailableChallengeForTeam = async (teamId: number): Promise => { + const factionId = await getFactionFromTeam(teamId) + const completedChallengesIds = [ + ...await getCompletedChallengesForTeam(teamId), + ...await getCompletedChallengesForFaction(factionId) + ] + const allChallenges = await getAllChallengesExcept(ChallengeType.Student) + const allChallengesIds = allChallenges.map(chall => chall.id as number) + const availableChallengeIds = allChallengesIds.filter(id => !completedChallengesIds.includes(id)); + return getChallengeFromIds(availableChallengeIds) +} + +export const getAvailableChallengeForFaction = async (factionId: number): Promise => { + const completedChallengesIds = await getCompletedChallengesForFaction(factionId) + console.log("completed: " + completedChallengesIds) + const allChallenges = await getChallengesOf(ChallengeType.Faction) + const allChallengesIds = allChallenges.map(chall => chall.id as number) + const availableChallengeIds = allChallengesIds.filter(id => !completedChallengesIds.includes(id)); + console.log("available: " + availableChallengeIds) + return getChallengeFromIds(availableChallengeIds) +} + export const countPoints = async (factionId: number): Promise => { //checking faction exist const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, factionId)); - if(!faction || faction.length === 0) throw new Error("No faction with id '" + faction + "'") + if(!faction || faction.length === 0) throw NoFaction(factionId) let points = 0; + //getting free challenges + const freeChallenges = await db.select().from(FreeToChallengeSchema).where(eq(FreeToChallengeSchema.factionId, factionId)) + freeChallenges.forEach(chall => points += chall.attributedPoints) + //getting every challenge associated with faction const factionChallenges = await db.select().from(factionTochallengeSchema).where(eq(factionTochallengeSchema.factionId, factionId)) factionChallenges.forEach(challenge => points += challenge.attributedPoints) @@ -123,6 +217,29 @@ export const countPoints = async (factionId: number): Promise => { return points } +export const countPointsForTeam = async (teamId: number): Promise => { + let points = 0; + + //getting every teamId who is associated with factionId + const factionTeams = await db.select().from(teamSchema).where(eq(teamSchema.id, teamId)) + const teamsId = factionTeams.map(team => team.id) + + //getting every challenge associated with every teams and add points + for (const teamId of teamsId) { + const challenges = await db.select().from(TeamTochallengeSchema).where(eq(TeamTochallengeSchema.teamId, teamId)); + challenges.forEach(challenge => points += challenge.attributedPoints) + //-----// + const users = await db.select().from(userSchema).where(eq(userSchema.team, teamId)); + //getting challenges associated to users + for(let user of users) { + const userChallenges = await db.select().from(StudentTochallengeSchema).where(eq(StudentTochallengeSchema.studentId, user.id)) + userChallenges.forEach(challenge => points += challenge.attributedPoints) + } + } + + return points +} + export const createChallenge = async (name: string, description: string, points: string, challType: ChallengeType) => { const newChallenge: challenge = {name: name, description: description, points: points, challType: challType}; try { @@ -313,7 +430,7 @@ async function completeChallengeToUser(challengeId: number, associatedId: number //get associated faction try { - const faction = await getFactionFromUserTeam(user[0].team as number) + const faction = await getFactionFromTeam(user[0].team as number) await addPoints(faction, attributedPoints) //associating the event await db.insert(StudentTochallengeSchema).values({ diff --git a/backend/src/services/team.service.ts b/backend/src/services/team.service.ts index cee87cd9..4751c9d8 100644 --- a/backend/src/services/team.service.ts +++ b/backend/src/services/team.service.ts @@ -2,6 +2,7 @@ import { teamSchema, Team } from "../schemas/team.schema" import { db } from "../database/db" import { eq } from 'drizzle-orm' import { timeEnd, timeStamp } from "console"; +import {countPointsForTeam} from "./challenge.service"; export const getAllTeams = async () => { try { @@ -11,6 +12,21 @@ export const getAllTeams = async () => { } } +export const getAllTeamsWithPoints = async () => { + try { + let result = [] + const teams = await db.select().from(teamSchema); + const ids = teams.map(team => team.id) + for (let i = 0; i < ids.length; i++) { + const points = await countPointsForTeam(ids[i]) + result.push({team: teams[i], points: points}) + } + return result + } catch (error) { + throw new Error("Failed to fetch teams. Please try again later."); + } +} + export const createTeam = async (name: string) => { try { const newTeam: Team = { name, isOfficial: false, faction: null, timeCode: 0}; diff --git a/backend/src/services/user.service.ts b/backend/src/services/user.service.ts index 289340aa..b54e9c58 100644 --- a/backend/src/services/user.service.ts +++ b/backend/src/services/user.service.ts @@ -3,7 +3,7 @@ import { userSchema, User, PermType } from '../schemas/user.schema'; import { newstudentSchema } from '../schemas/newstudent.schema'; import { roleSchema, userToRoleSchema } from '../schemas/role.schema'; import { db } from "../database/db" -import { eq, and, is } from 'drizzle-orm' +import {eq, and, is, ne, isNotNull} from 'drizzle-orm' import { uuid } from 'drizzle-orm/pg-core'; export const getAllUsers = async () => { @@ -20,7 +20,30 @@ export const getAllUsers = async () => { discord_id: userSchema.discord_id, connection_number: userSchema.connection_number, team_id: userSchema.team, - }).from(userSchema); + }).from(userSchema).where(eq(userSchema.permission, PermType.NewStudent)); + } catch (error) { + throw new Error("Failed to fetch users. Please try again later."); + } +} + +export const getAllCe = async () => { + try { + return await db.select({ + id: userSchema.id, + first_name: userSchema.first_name, + last_name: userSchema.last_name, + email: userSchema.email, + branch: userSchema.branch, + permission: userSchema.permission, + birthday: userSchema.birthday, + contact: userSchema.contact, + discord_id: userSchema.discord_id, + connection_number: userSchema.connection_number, + team_id: userSchema.team, + }).from(userSchema).where(and( + eq(userSchema.permission, PermType.Student), + isNotNull(userSchema.team) + )); } catch (error) { throw new Error("Failed to fetch users. Please try again later."); } @@ -280,3 +303,85 @@ export const getAllMembersTeam = async (team_id: number) => { throw new Error("Failed to get the team's timecode. Please try again later."); } } + +type UserData = { + etu_number: string + first_name: string, + last_name: string, + email: string, + phone: string, + new: boolean, + ce: boolean, + team_number: number | null, + orga: boolean, + mission: string, + major: boolean +} + +export async function getInfo(emails: string[]): Promise { + //checking faction exist + let list = [] + for (let email of emails) { + const user = await db.select().from(userSchema).where(eq(userSchema.email, email)); + if(!user || user.length === 0) throw new Error("No user with mail '" + email + "'") + list.push([ + "", + user[0].first_name, + user[0].last_name, + email, + "", + isNew(user[0]), + isCe(user[0]), + user[0].team, + isOrga(user[0]), + "", + isMajor(user[0]) + ]) + console.log(list) + } + return list +} + +/* + list.push({ + etu_number: "", + first_name: user[0].first_name, + last_name: user[0].last_name, + email: email, + phone: "", + new: isNew(user[0]), + ce: isCe(user[0]), + team_number: user[0].team, + orga: isOrga(user[0]), + mission: "", + major: isMajor(user[0]) + }) + */ + +function isCe(user: User) { + return user.permission === PermType.Student && user.team !== undefined +} + +function isMajor(user: User): boolean { + if(!user.birthday) return false + const birthDate = new Date(user.birthday); + const today = new Date(); + + let age = today.getFullYear() - birthDate.getFullYear(); + const monthDifference = today.getMonth() - birthDate.getMonth(); + + // Si l'anniversaire n'est pas encore passé cette année, on soustrait 1 + if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) { + age--; + } + + return age >= 18; +} + +function isOrga(user: User) { + return user.permission !== PermType.NewStudent +} + +function isNew(user: User) { + return user.permission === PermType.NewStudent +} diff --git a/backend/src/utils/challenge.ts b/backend/src/utils/challenge.ts index 303d362a..b679e3d9 100644 --- a/backend/src/utils/challenge.ts +++ b/backend/src/utils/challenge.ts @@ -1,21 +1,73 @@ import {db} from "../database/db"; import {teamSchema} from "../schemas/team.schema"; -import {eq} from "drizzle-orm"; -import {userSchema} from "../schemas/user.schema"; +import {eq, inArray, ne} from "drizzle-orm"; +import {User, userSchema} from "../schemas/user.schema"; +import {NoFaction, NoTeam, NoUser} from "../error/user"; +import {factionSchema} from "../schemas/faction.schema"; +import { + challenge, + challengeSchema, + ChallengeType, factionTochallenge, factionTochallengeSchema, studentTochallenge, + StudentTochallengeSchema, + teamTochallenge, TeamTochallengeSchema +} from "../schemas/challenge.schema"; -export async function getFactionFromUserTeam(userTeam: number): Promise { +export async function getFactionFromTeam(userTeam: number): Promise { //get associated faction const team = await db.select().from(teamSchema).where(eq(teamSchema.id, userTeam)) - if(!team || team.length === 0) throw new Error('No team with id ' + userTeam) + if(!team || team.length === 0) throw NoTeam(userTeam) return team[0].faction as number } export async function getFactionFromUserId(userId: number): Promise { //get user const user = await db.select().from(userSchema).where(eq(userSchema.id, userId)) - if(!user || user.length === 0) throw new Error("No user with id '" + userId + "'") + if(!user || user.length === 0) throw NoUser(userId) //get associated faction const team = await db.select().from(teamSchema).where(eq(teamSchema.id, user[0].team as number)) - if(!team || team.length === 0) throw new Error('No team with id ' + user[0].team) + if(!team || team.length === 0) throw NoTeam(user[0].team) return team[0].faction as number +} + +export async function getFactionFromUser(user: User): Promise { + //get associated faction + const team = await db.select().from(teamSchema).where(eq(teamSchema.id, user.team as number)) + if(!team || team.length === 0) throw NoTeam(team[0].id) + return team[0].faction as number +} + +export async function getChallengeFromIds(challengesIds: number[]): Promise { + if(!challengesIds || challengesIds.length === 0) return [] + return db.select() + .from(challengeSchema) + .where(inArray(challengeSchema.id, challengesIds)); +} + +export async function getAllChallenges(): Promise { + return db.select().from(challengeSchema) +} + +export async function getChallengesOf(type: ChallengeType): Promise { + return db.select().from(challengeSchema).where(eq(challengeSchema.challType, type)) +} + +export async function getAllChallengesExcept(type: ChallengeType): Promise { + return db.select().from(challengeSchema).where(ne(challengeSchema.challType, type)) +} + +export async function getTeamAndFactionFromUser(user: User): Promise<{teamId: number, factionId: number}> { + //get associated faction + const team = await db.select().from(teamSchema).where(eq(teamSchema.id, user.team as number)) + if(!team || team.length === 0) throw NoTeam(team[0].id) + //get faction + const faction = await db.select().from(factionSchema).where(eq(factionSchema.id, team[0].faction as number)) + if(!faction || faction.length === 0) throw NoFaction(team[0].id) + return {teamId: team[0].id, factionId: faction[0].id} +} + +export async function getTeamAndFactionFromUserId(user: number): Promise<{teamId: number, factionId: number}> { + //get user + const userdb = await db.select().from(userSchema).where(eq(userSchema.id, user)) + if(!userdb || userdb.length === 0) throw NoUser(user) + return await getTeamAndFactionFromUser(userdb[0]) } \ No newline at end of file diff --git a/frontend/src/components/admin/users/Actions.tsx b/frontend/src/components/admin/users/Actions.tsx index 90fe0294..fac5ff4d 100644 --- a/frontend/src/components/admin/users/Actions.tsx +++ b/frontend/src/components/admin/users/Actions.tsx @@ -9,6 +9,7 @@ import { User, newStudent } from '../../../services/interfaces' import { getAllUsers } from '../../../services/requests' import { toTable } from '../../utils/Tables' import { deleteUUID, getAllUUID, syncUUID } from '../../../services/requests/newstudent'; +import {api} from "../../../services/api"; export const AddToTeam = () => { const [users, setUsers] = useState([] as any) @@ -44,6 +45,59 @@ export const AddToTeam = () => { ) } +//to get data for wei bus distribution +export const GetDatas = () => { + const [users, setUsers] = useState([] as any[]); + const [team, setTeam] = useState({} as any); + + // Fonction pour gérer le chargement du fichier + const handleFileUpload = async (event: React.ChangeEvent) => { + const file = event.target.files?.[0]; + if (!file) return; + + const reader = new FileReader(); + reader.onload = (e) => { + const content = e.target?.result as string; + console.log(content) + const lines = content.split('\n').map(line => line.trim()).filter(line => line); + setUsers(lines); + }; + reader.readAsText(file); + }; + + const Submit = async () => { + const t = await api.post("user/getInfo", {email: users}) + const data = t.data.data + let stringContent = "" + for (const line of data) { + stringContent += (line.toString() + "\n") + } + const blob = new Blob([stringContent], { type: 'text/plain' }); // Utilisation de 'text/plain' pour du texte brut + const url = URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = url; + link.download = 'user_info.txt'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // Réinitialisation des états après soumission + setUsers([]); + setTeam({}); + }; + + return ( +
+
+ +
+ + +
+ ); +}; + export const ChangePermission = () => { const [user, setUser] = useState({} as any) const [perm, setPerm] = useState({} as any) diff --git a/frontend/src/components/admin/users/UserAdminSection.tsx b/frontend/src/components/admin/users/UserAdminSection.tsx index 23cbf09f..44ea9539 100644 --- a/frontend/src/components/admin/users/UserAdminSection.tsx +++ b/frontend/src/components/admin/users/UserAdminSection.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import AdminSection from '../AdminSection'; -import { AddToTeam, ChangePermission, DeleteUser, ManageUUIDs, TableUUIDs, TableUser } from './Actions'; +import {AddToTeam, ChangePermission, DeleteUser, ManageUUIDs, TableUUIDs, TableUser, GetDatas} from './Actions'; import { AdminAction } from '../AdminSection'; import { getRole } from '../../../services/requests'; @@ -51,6 +51,11 @@ const UserAdminSection: React.FC = () => { title: 'Affichage cléfs de connexions unique', form: , }, + { + title: 'Récupération données WEI', + form: , + }, + ]; const filteredActions = actions.filter(action => { diff --git a/frontend/src/components/challenge/student/Actions.tsx b/frontend/src/components/challenge/AnimAction.tsx similarity index 63% rename from frontend/src/components/challenge/student/Actions.tsx rename to frontend/src/components/challenge/AnimAction.tsx index 38507aa6..9ea05870 100644 --- a/frontend/src/components/challenge/student/Actions.tsx +++ b/frontend/src/components/challenge/AnimAction.tsx @@ -1,21 +1,12 @@ -import React, { useEffect, useState } from 'react'; +import React, {useEffect, useState} from 'react'; import Select from 'react-select' -import { - createTeam, - addToFaction, - deleteTeam, - getAllTeams, - renameTeam, - validateTeam, -} from '../../../services/requests/teams'; -import { ToastContainer, toast } from 'react-toastify'; +import {ToastContainer} from 'react-toastify'; import "react-toastify/dist/ReactToastify.css"; -import {Challenge, ChallType} from "../../../services/interfaces"; -import {toTable} from "../../utils/Tables"; -import {getChallenges, unvalidChallenge, validChallenge} from "../../../services/requests/challenges"; -import {handleError, toId} from "../../utils/Submit"; -import {changePermission} from "../../../services/requests/users"; -import {Challenges, Factions, Users} from "../../utils/Select"; +import {Challenge, ChallType} from "../../services/interfaces"; +import {toTable} from "../utils/Tables"; +import {getChallenges, unvalidChallenge, validChallenge} from "../../services/requests/challenges"; +import {handleError} from "../utils/Submit"; +import {Ces, Challenges, Choice, Factions, Teams, Users} from "../utils/Select"; interface TableChallengeType { type: ChallType @@ -28,7 +19,7 @@ export const TableChallenge: React.FC = ({ type }) => { useEffect(() => { const fetchChallenges = async () => { try { - const teams = await getChallenges(type); + const teams = await getChallenges(type, Choice.ALL, undefined); setChallenges(teams) } catch (error) { console.error('Error fetching challenges:', error); @@ -40,15 +31,15 @@ export const TableChallenge: React.FC = ({ type }) => { } export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [faction, setFaction] = useState({} as any) + const [value, setValue] = useState({} as any) const [challenge, setChallenge] = useState({} as any) + const [choices, setChoices] = useState({} as any) const [points, setPoints] = useState(0) const [text, setText] = useState("") const Submit = async () => { - const id = toId(faction) - await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) - setFaction({}) + await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, value.value, challenge.value, points, text) + setValue({}) setChallenge({}) setPoints(0) setText("") @@ -58,12 +49,14 @@ export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => {
{ setText(chall.description + " : " + chall.points) setChallenge(chall) @@ -94,19 +87,18 @@ export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { />
- +
) } - export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [student, setUsers] = useState({} as any) + const [value, setValue] = useState({} as any) const [challenge, setChallenge] = useState({} as any) const Submit = async () => { - await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidChallenge, challenge.value, student.value) - setUsers({}) + await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidChallenge, challenge.value, value.value) + setValue({}) setChallenge({}) } @@ -114,18 +106,20 @@ export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => {
setChallenge(chall)} value={challenge} />
- +
) diff --git a/frontend/src/components/challenge/AnimSection.tsx b/frontend/src/components/challenge/BaseAnimSection.tsx similarity index 90% rename from frontend/src/components/challenge/AnimSection.tsx rename to frontend/src/components/challenge/BaseAnimSection.tsx index df6f68cd..3d2873c0 100644 --- a/frontend/src/components/challenge/AnimSection.tsx +++ b/frontend/src/components/challenge/BaseAnimSection.tsx @@ -9,7 +9,7 @@ export interface SectionProps { actions: AnimAction[]; } -const AnimSection: React.FC = ({ actions }) => { +const BaseAnimSection: React.FC = ({ actions }) => { const [selectedAction, setSelectedAction] = useState(null); const handleActionClick = (action: AnimAction) => { @@ -36,4 +36,4 @@ const AnimSection: React.FC = ({ actions }) => { ); }; -export default AnimSection; +export default BaseAnimSection; diff --git a/frontend/src/components/challenge/faction/Actions.tsx b/frontend/src/components/challenge/faction/Actions.tsx deleted file mode 100644 index 5a56a7aa..00000000 --- a/frontend/src/components/challenge/faction/Actions.tsx +++ /dev/null @@ -1,137 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import Select from 'react-select' -import { - createTeam, - addToFaction, - deleteTeam, - getAllTeams, - renameTeam, - validateTeam, -} from '../../../services/requests/teams'; -import { ToastContainer, toast } from 'react-toastify'; -import "react-toastify/dist/ReactToastify.css"; -import {Challenge, ChallType} from "../../../services/interfaces"; -import {toTable} from "../../utils/Tables"; -import { - getChallenges, - unvalidChallenge, - unvalidFreeChallenge, - validChallenge -} from "../../../services/requests/challenges"; -import {handleError, toId} from "../../utils/Submit"; -import {changePermission} from "../../../services/requests/users"; -import {Challenges, Factions, Users} from "../../utils/Select"; - -interface TableChallengeType { - type: ChallType -} - -export const TableChallenge: React.FC = ({ type }) => { - - const [challenges, setChallenges] = useState([]); - - useEffect(() => { - const fetchChallenges = async () => { - try { - const teams = await getChallenges(type); - setChallenges(teams) - } catch (error) { - console.error('Error fetching challenges:', error); - } - }; - fetchChallenges(); - }, []); - return challenges.length > 0 ? toTable(challenges) : null; -} - -export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [faction, setFaction] = useState({} as any) - const [challenge, setChallenge] = useState({} as any) - const [points, setPoints] = useState(0) - const [text, setText] = useState("") - - const Submit = async () => { - const id = toId(faction) - await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) - setFaction({}) - setChallenge({}) - setPoints(0) - setText("") - } - - return ( -
-
- { - setText(chall.description + " : " + chall.points) - setChallenge(chall) - }} - value={challenge} - /> - -
-
-
- - setPoints(Number(e.target.value))} - /> -
- - {/* Input pour le texte */} -
- - setText(e.target.value)} - /> -
-
- - -
- ) -} - -export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [faction, setFaction] = useState({} as any) - const [challenge, setChallenge] = useState({} as any) - - const Submit = async () => { - await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidChallenge, challenge.value, faction.value) - setFaction({}) - setChallenge({}) - } - - return ( -
-
- setChallenge(chall)} - value={challenge} - /> - -
- - -
- ) -} \ No newline at end of file diff --git a/frontend/src/components/challenge/faction/ChallFactionSection.tsx b/frontend/src/components/challenge/faction/ChallFactionSection.tsx index ad3f50a2..8531c66a 100644 --- a/frontend/src/components/challenge/faction/ChallFactionSection.tsx +++ b/frontend/src/components/challenge/faction/ChallFactionSection.tsx @@ -1,9 +1,9 @@ import React, {useEffect, useState} from 'react'; -import {TableChallenge, UnvalidChallenge, ValidChallenge} from './Actions'; import {getRole} from '../../../services/requests'; -import AnimSection from "../AnimSection"; +import BaseAnimSection from "../BaseAnimSection"; import {AdminAction} from "../../admin/AdminSection"; import {ChallType} from "../../../services/interfaces"; +import {TableChallenge, UnvalidChallenge, ValidChallenge} from "../AnimAction"; const ChallFactionSection: React.FC = () => { @@ -43,7 +43,7 @@ const ChallFactionSection: React.FC = () => { ]; return ( - + ); }; diff --git a/frontend/src/components/challenge/free/ChallFreeSection.tsx b/frontend/src/components/challenge/free/ChallFreeSection.tsx index b39382c8..d5acd33a 100644 --- a/frontend/src/components/challenge/free/ChallFreeSection.tsx +++ b/frontend/src/components/challenge/free/ChallFreeSection.tsx @@ -1,7 +1,7 @@ import React, {useEffect, useState} from 'react'; import {TableChallenge, UnvalidChallenge, ValidChallenge} from './FreeActions'; import {getRole} from '../../../services/requests'; -import AnimSection from "../AnimSection"; +import BaseAnimSection from "../BaseAnimSection"; import {AdminAction} from "../../admin/AdminSection"; import {ChallType} from "../../../services/interfaces"; @@ -43,7 +43,7 @@ const ChallFreeSection: React.FC = () => { ]; return ( - + ); }; diff --git a/frontend/src/components/challenge/free/FreeActions.tsx b/frontend/src/components/challenge/free/FreeActions.tsx index 209d4dda..30559625 100644 --- a/frontend/src/components/challenge/free/FreeActions.tsx +++ b/frontend/src/components/challenge/free/FreeActions.tsx @@ -1,26 +1,12 @@ -import React, { useEffect, useState } from 'react'; +import React, {useEffect, useState} from 'react'; import Select from 'react-select' -import { - createTeam, - addToFaction, - deleteTeam, - getAllTeams, - renameTeam, - validateTeam, -} from '../../../services/requests/teams'; -import { ToastContainer, toast } from 'react-toastify'; +import {ToastContainer} from 'react-toastify'; import "react-toastify/dist/ReactToastify.css"; import {Challenge, ChallType} from "../../../services/interfaces"; import {toTable} from "../../utils/Tables"; -import { - getChallenges, - unvalidFreeChallenge, - validChallenge, - validFreeChallenge -} from "../../../services/requests/challenges"; +import {getChallenges, unvalidFreeChallenge, validFreeChallenge} from "../../../services/requests/challenges"; import {handleError, toId} from "../../utils/Submit"; -import {changePermission} from "../../../services/requests/users"; -import {Challenges, Factions, getFreeChallengeText, Teams, Users} from "../../utils/Select"; +import {Choice, Factions, getFreeChallengeText} from "../../utils/Select"; interface TableChallengeType { type: ChallType @@ -33,7 +19,7 @@ export const TableChallenge: React.FC = ({ type }) => { useEffect(() => { const fetchChallenges = async () => { try { - const teams = await getChallenges(type); + const teams = await getChallenges(type, Choice.ALL, undefined); setChallenges(teams) } catch (error) { console.error('Error fetching challenges:', error); diff --git a/frontend/src/components/challenge/student/ChallStudentSection.tsx b/frontend/src/components/challenge/student/ChallStudentSection.tsx index d71338ff..2579d78d 100644 --- a/frontend/src/components/challenge/student/ChallStudentSection.tsx +++ b/frontend/src/components/challenge/student/ChallStudentSection.tsx @@ -1,9 +1,9 @@ import React, {useEffect, useState} from 'react'; -import {TableChallenge, UnvalidChallenge, ValidChallenge} from './Actions'; import {getRole} from '../../../services/requests'; -import AnimSection from "../AnimSection"; +import BaseAnimSection from "../BaseAnimSection"; import {AdminAction} from "../../admin/AdminSection"; import {ChallType} from "../../../services/interfaces"; +import {TableChallenge, UnvalidChallenge, ValidChallenge} from "../AnimAction"; const ChallStudentSection: React.FC = () => { @@ -44,7 +44,7 @@ const ChallStudentSection: React.FC = () => { ]; return ( - + ); }; diff --git a/frontend/src/components/challenge/student_or_ce/Actions.tsx b/frontend/src/components/challenge/student_or_ce/Actions.tsx deleted file mode 100644 index 43e611ed..00000000 --- a/frontend/src/components/challenge/student_or_ce/Actions.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import Select from 'react-select' -import { - createTeam, - addToFaction, - deleteTeam, - getAllTeams, - renameTeam, - validateTeam, -} from '../../../services/requests/teams'; -import { ToastContainer, toast } from 'react-toastify'; -import "react-toastify/dist/ReactToastify.css"; -import {Challenge, ChallType} from "../../../services/interfaces"; -import {toTable} from "../../utils/Tables"; -import {getChallenges, validChallenge} from "../../../services/requests/challenges"; -import {handleError, toId} from "../../utils/Submit"; -import {changePermission} from "../../../services/requests/users"; -import {Challenges, Factions, Users} from "../../utils/Select"; - -interface TableChallengeType { - type: ChallType -} - -export const TableChallenge: React.FC = ({ type }) => { - - const [challenges, setChallenges] = useState([]); - - useEffect(() => { - const fetchChallenges = async () => { - try { - const teams = await getChallenges(type); - setChallenges(teams) - } catch (error) { - console.error('Error fetching challenges:', error); - } - }; - fetchChallenges(); - }, []); - return challenges.length > 0 ? toTable(challenges) : null; -} - -export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [faction, setFaction] = useState({} as any) - const [challenge, setChallenge] = useState({} as any) - const [points, setPoints] = useState(0) - const [text, setText] = useState("") - - const Submit = async () => { - const id = toId(faction) - await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) - setFaction({}) - setChallenge({}) - setPoints(0) - setText("") - } - - return ( -
-
- { - setText(chall.description + " : " + chall.points) - setChallenge(chall) - }} - value={challenge} - /> - -
-
-
- - setPoints(Number(e.target.value))} - /> -
- - {/* Input pour le texte */} -
- - setText(e.target.value)} - /> -
-
- - -
- ) -} \ No newline at end of file diff --git a/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx b/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx index d6d61979..6e68b0f5 100644 --- a/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx +++ b/frontend/src/components/challenge/student_or_ce/ChallStudentCeSection.tsx @@ -1,10 +1,9 @@ import React, {useEffect, useState} from 'react'; -import {TableChallenge, ValidChallenge} from './Actions'; import {getRole} from '../../../services/requests'; -import AnimSection from "../AnimSection"; +import BaseAnimSection from "../BaseAnimSection"; import {AdminAction} from "../../admin/AdminSection"; import {ChallType} from "../../../services/interfaces"; -import {UnvalidChallenge} from "../student/Actions"; +import {TableChallenge, UnvalidChallenge, ValidChallenge} from "../AnimAction"; const ChallStudentCeSection: React.FC = () => { @@ -45,7 +44,7 @@ const ChallStudentCeSection: React.FC = () => { ]; return ( - + ); }; diff --git a/frontend/src/components/challenge/team/ChallTeamSection.tsx b/frontend/src/components/challenge/team/ChallTeamSection.tsx index 7bb5c689..708bfc88 100644 --- a/frontend/src/components/challenge/team/ChallTeamSection.tsx +++ b/frontend/src/components/challenge/team/ChallTeamSection.tsx @@ -1,9 +1,9 @@ import React, {useEffect, useState} from 'react'; -import {TableChallenge, UnvalidChallenge, ValidChallenge} from './TeamActions'; import {getRole} from '../../../services/requests'; -import AnimSection from "../AnimSection"; +import BaseAnimSection from "../BaseAnimSection"; import {AdminAction} from "../../admin/AdminSection"; import {ChallType} from "../../../services/interfaces"; +import {TableChallenge, UnvalidChallenge, ValidChallenge} from "../AnimAction"; const ChallTeamSection: React.FC = () => { @@ -43,7 +43,7 @@ const ChallTeamSection: React.FC = () => { ]; return ( - + ); }; diff --git a/frontend/src/components/challenge/team/TeamActions.tsx b/frontend/src/components/challenge/team/TeamActions.tsx deleted file mode 100644 index c9daddcc..00000000 --- a/frontend/src/components/challenge/team/TeamActions.tsx +++ /dev/null @@ -1,131 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import Select from 'react-select' -import { - createTeam, - addToFaction, - deleteTeam, - getAllTeams, - renameTeam, - validateTeam, -} from '../../../services/requests/teams'; -import { ToastContainer, toast } from 'react-toastify'; -import "react-toastify/dist/ReactToastify.css"; -import {Challenge, ChallType} from "../../../services/interfaces"; -import {toTable} from "../../utils/Tables"; -import {getChallenges, unvalidChallenge, validChallenge} from "../../../services/requests/challenges"; -import {handleError, toId} from "../../utils/Submit"; -import {changePermission} from "../../../services/requests/users"; -import {Challenges, Factions, Teams, Users} from "../../utils/Select"; - -interface TableChallengeType { - type: ChallType -} - -export const TableChallenge: React.FC = ({ type }) => { - - const [challenges, setChallenges] = useState([]); - - useEffect(() => { - const fetchChallenges = async () => { - try { - const teams = await getChallenges(type); - setChallenges(teams) - } catch (error) { - console.error('Error fetching challenges:', error); - } - }; - fetchChallenges(); - }, []); - return challenges.length > 0 ? toTable(challenges) : null; -} - -export const ValidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [faction, setFaction] = useState({} as any) - const [challenge, setChallenge] = useState({} as any) - const [points, setPoints] = useState(0) - const [text, setText] = useState("") - - const Submit = async () => { - const id = toId(faction) - await handleError("Challenge validé !", "Challenge déjà complété.", validChallenge, faction.value, challenge.value, points, text) - setFaction({}) - setChallenge({}) - setPoints(0) - setText("") - } - - return ( -
-
- { - setText(chall.description + " : " + chall.points) - setChallenge(chall) - }} - value={challenge} - /> - -
-
-
- - setPoints(Number(e.target.value))} - /> -
- - {/* Input pour le texte */} -
- - setText(e.target.value)} - /> -
-
- - -
- ) -} -export const UnvalidChallenge: React.FC<{type: ChallType}> = ({type}) => { - const [team, setTeam] = useState({} as any) - const [challenge, setChallenge] = useState({} as any) - - const Submit = async () => { - await handleError("Challenge unvalidé !", "Challenge non complété.", unvalidChallenge, challenge.value, team.value) - setTeam({}) - setChallenge({}) - } - - return ( -
-
- setChallenge(chall)} - value={challenge} - /> - -
- - -
- ) -} \ No newline at end of file diff --git a/frontend/src/components/factions/FactionsAffichage.tsx b/frontend/src/components/factions/FactionsAffichage.tsx index 0a427ae4..74724796 100644 --- a/frontend/src/components/factions/FactionsAffichage.tsx +++ b/frontend/src/components/factions/FactionsAffichage.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Faction, Team } from '../../services/interfaces'; import "./Factions.css"; -import { getAllTeams } from '../../services/requests/teams'; +import {getAllTeams, getAllTeamsWithPoints} from '../../services/requests/teams'; interface FactionsAffichageProps { faction: Faction; @@ -9,19 +9,19 @@ interface FactionsAffichageProps { const FactionsAffichage: React.FC = ({ faction }) => { - const [allTeams, setAllTeams] = useState([]); + const [allTeams, setAllTeams] = useState<{team: Team, points: number}[]>(); useEffect(() => { const fetchData = async () => { try { - const response = await getAllTeams(); - const filteredTeams = response.filter((team:Team) => team.faction === faction.id); + const response = await getAllTeamsWithPoints(); + const filteredTeams = response.filter((team:{team: Team, points: number}) => team.team.faction === faction.id); setAllTeams(filteredTeams); } catch (error) { console.error('Error fetching data:', error); } }; - fetchData(); + fetchData().then(); }, []); return ( @@ -29,9 +29,9 @@ const FactionsAffichage: React.FC = ({ faction }) => {

Equipes

- {allTeams.length > 0 ? ( - allTeams.map((team: Team, index: number) => ( -

{team.name}

+ {!allTeams ?

Chargement...

: allTeams.length > 0 ? ( + allTeams.map((team: {team: Team, points: number}, index: number) => ( +

{team.team.name} - {team.points}

)) ) : (

La faction ne comprend pas d'équipe

diff --git a/frontend/src/components/utils/Select.tsx b/frontend/src/components/utils/Select.tsx index 1216b9c9..b3729cf1 100644 --- a/frontend/src/components/utils/Select.tsx +++ b/frontend/src/components/utils/Select.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from "react" import {Role, Faction, User, Team, Event, newStudent, Perm, Challenge, ChallType} from '../../services/interfaces' -import { getAllFactions, getAllTeams, getAllUsers } from '../../services/requests' +import {getAllCe, getAllFactions, getAllTeams, getAllUsers} from '../../services/requests' import { getAllRoles } from "../../services/requests/roles" import { getActiveEvents, getInactiveEvents } from "../../services/requests/events" import { getAllUUID } from "../../services/requests/newstudent" @@ -101,13 +101,19 @@ export const Teams = () => { return options } -export const Challenges = (challType: ChallType) => { +export enum Choice { + ALL = "all", + AVAILABLE = "available", + COMPLETED = "completed" +} + +export const Challenges = (challType: ChallType, filter: Choice, associateId: number | undefined) => { const [options, setOptions] = useState([]) useEffect(() => { const fetchData = async () => { try { - const response = await getChallenges(challType) + const response = await getChallenges(challType, filter, associateId) const challOptions = response.map((chall: Challenge) => { return { value: chall.id, @@ -123,7 +129,7 @@ export const Challenges = (challType: ChallType) => { } fetchData() - }, []) + }, [associateId]) return options } @@ -149,22 +155,20 @@ export const getFreeChallengeText = async (factionId: number): Promise<{value: s } -export const ValidedChallenge = (challType: ChallType) => { + +export const Users = () => { const [options, setOptions] = useState([]) useEffect(() => { const fetchData = async () => { try { - const response = await getChallenges(challType) - const challOptions = response.map((chall: Challenge) => { - return { - value: chall.id, - label: chall.name, - description: chall.description, - points: chall.points - } - }) - setOptions(challOptions) + const response = await getAllUsers() + const usersOptions = response.map((user: User) => ({ + value: user.id, + label: `${user.first_name} ${user.last_name}`, + email : user.email, + })) + setOptions(usersOptions) } catch (error) { console.error('Error fetching data:', error) } @@ -176,14 +180,13 @@ export const ValidedChallenge = (challType: ChallType) => { return options } - -export const Users = () => { +export const Ces = () => { const [options, setOptions] = useState([]) - + console.log("get ce") useEffect(() => { const fetchData = async () => { try { - const response = await getAllUsers() + const response = await getAllCe() const usersOptions = response.map((user: User) => ({ value: user.id, label: `${user.first_name} ${user.last_name}`, diff --git a/frontend/src/services/requests.ts b/frontend/src/services/requests.ts index 81e3433d..d1525c9b 100644 --- a/frontend/src/services/requests.ts +++ b/frontend/src/services/requests.ts @@ -1,11 +1,18 @@ import { api } from './api'; // Obtention de la liste des Utilisateurs enregistrés dans la db +//NE RETOURNE PAS LES CE export const getAllUsers = async () => { const response = await api.get('user/all') return response?.data.data } +// Obtention de la liste des Ce enregistrés dans la db +export const getAllCe = async () => { + const response = await api.get('user/ce/all') + return response?.data.data +} + // Obtention de la liste des équipes enregistrées dans la db export const getAllTeams = async () => { const response = await api.get('team/all') diff --git a/frontend/src/services/requests/challenges.ts b/frontend/src/services/requests/challenges.ts index 4335ff2c..21820eee 100644 --- a/frontend/src/services/requests/challenges.ts +++ b/frontend/src/services/requests/challenges.ts @@ -1,5 +1,6 @@ -import { api } from "../api"; +import {api} from "../api"; import {ChallType} from "../interfaces"; +import {Choice} from "../../components/utils/Select"; // Obtention de la liste des challenges enregistrées dans la db export const getAllChallenges = async () => { @@ -7,8 +8,9 @@ export const getAllChallenges = async () => { return response.data.data; }; -export const getChallenges = async (type: ChallType) => { - const response = await api.get("challenge/all" + type); +export const getChallenges = async (type: ChallType, filter: Choice, associatedId: number | undefined) => { + if(filter !== Choice.ALL && associatedId === undefined) return [] + const response = await api.post("challenge/all" + type, {filter: filter, associatedId: associatedId}); return response.data.data; }; @@ -20,7 +22,6 @@ export const getAllFreeChallengesTexts = async (factionId: number) => { }; export const validChallenge = async (associatedId: number, challId: number, attributedPoints: number, text: string|null) => { - console.log("ratio") return await api.post('challenge/valid', { associatedId, challId, diff --git a/frontend/src/services/requests/teams.ts b/frontend/src/services/requests/teams.ts index b39677f9..ee5426ca 100644 --- a/frontend/src/services/requests/teams.ts +++ b/frontend/src/services/requests/teams.ts @@ -50,6 +50,11 @@ export const getAllTeams = async () => { return response.data.data; }; +export const getAllTeamsWithPoints = async () => { + const response = await api.get("team/allWithPoints"); + return response.data.data; +}; + export const getAllMembersTeam = async (id : number) => { const response = await api.get("team/getallmembers/"+id); return response.data.data; From e66f314e65cf8e46b450458c8d5e80ad40c4c453 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 15:32:00 +0200 Subject: [PATCH 12/15] REmove useless import --- frontend/src/components/admin/users/Actions.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/admin/users/Actions.tsx b/frontend/src/components/admin/users/Actions.tsx index 06f56093..86be27c2 100644 --- a/frontend/src/components/admin/users/Actions.tsx +++ b/frontend/src/components/admin/users/Actions.tsx @@ -10,7 +10,6 @@ import { getAllUsers } from '../../../services/requests' import { toTable } from '../../utils/Tables' import { deleteNewStudent, getAllNewStudent, syncNewStudent } from '../../../services/requests/newstudent'; import { resetPasswordAdmin } from '../../../services/requests/auth'; -import { deleteUUID, getAllUUID, syncUUID } from '../../../services/requests/newstudent'; import {api} from "../../../services/api"; export const AddToTeam = () => { From ff32c3a7c2604e1991b37adb4aa8dac5f693ac4c Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 15:33:29 +0200 Subject: [PATCH 13/15] Add gitignore for .env --- backend/.gitignore | 1 + frontend/.gitignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 backend/.gitignore create mode 100644 frontend/.gitignore diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file From 76a6376f753d00321d6c64ab5972b49d614cc834 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 15:58:05 +0200 Subject: [PATCH 14/15] Fix problems of migration. --- backend/src/controllers/challenge.controller.ts | 1 - backend/src/controllers/team.controller.ts | 7 +++++-- backend/src/routes/team.routes.ts | 3 +-- backend/src/services/team.service.ts | 2 +- frontend/src/services/requests/teams.ts | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/src/controllers/challenge.controller.ts b/backend/src/controllers/challenge.controller.ts index 4124d51f..db7444ee 100644 --- a/backend/src/controllers/challenge.controller.ts +++ b/backend/src/controllers/challenge.controller.ts @@ -210,7 +210,6 @@ export const getCompletedChallengeForTeam = async (req: Request, res: Response, export const getCompletedChallengeForFaction = async (req: Request, res: Response, next: NextFunction) => { const { associatedId } = req.body; - console.log("yoooo") try { const data = await getChallengeFromIds(await service.getCompletedChallengesForFaction(associatedId)); console.log(data) diff --git a/backend/src/controllers/team.controller.ts b/backend/src/controllers/team.controller.ts index 943888e6..6a1a38cd 100644 --- a/backend/src/controllers/team.controller.ts +++ b/backend/src/controllers/team.controller.ts @@ -16,10 +16,13 @@ export const getAllTeams = async (req: Request, res: Response, next: NextFunctio } export const getAllTeamsWithPoints = async (req: Request, res: Response, next: NextFunction) => { + console.log("fetch teamdezbyfuezvfuerfyzu") try { + console.log("fetch team") const data = await service.getAllTeamsWithPoints(); Ok(res, { data }); } catch (error) { + console.log("error") Error(res, { error }); } } @@ -27,7 +30,7 @@ export const getAllTeamsWithPoints = async (req: Request, res: Response, next: N export const getTeam = async (req: Request, res: Response, next: NextFunction) => { const { id } = req.params; const idNumber = parseInt(id, 10); - + console.log("pas censé 1") if (isNaN(idNumber)) return Error(res, { msg : 'Could not parse Id' }); try { @@ -54,7 +57,7 @@ export const createTeam = async (req: Request, res: Response, next: NextFunction export const deleteTeam = async (req: Request, res: Response, next: NextFunction) => { const { id } = req.params; const idNumber = parseInt(id, 10); - + console.log("pas censé 2") if (isNaN(idNumber)) return Error(res, { msg : 'could not parse Id' }); try { diff --git a/backend/src/routes/team.routes.ts b/backend/src/routes/team.routes.ts index 602a3cf5..aaa0aa1d 100644 --- a/backend/src/routes/team.routes.ts +++ b/backend/src/routes/team.routes.ts @@ -7,8 +7,7 @@ const teamRouter = express.Router(); teamRouter.post('/register',isTokenValid, tc.registerTeam); teamRouter.post('', isAdminCE, tc.createTeam); teamRouter.get('/all',isTokenValid, tc.getAllTeams); -teamRouter.get('/:id',isTokenValid, tc.getTeam); -teamRouter.get('/allWithPoints', tc.getAllTeamsWithPoints); +teamRouter.get('/teamsWithPoints', isTokenValid, tc.getAllTeamsWithPoints); teamRouter.get('/:id', isAdminCE, tc.getTeam); teamRouter.delete('/:id', isAdminCE, tc.deleteTeam); teamRouter.put('/addtofaction', isAdminCE, tc.addToFaction); diff --git a/backend/src/services/team.service.ts b/backend/src/services/team.service.ts index da2d37c7..d635b984 100644 --- a/backend/src/services/team.service.ts +++ b/backend/src/services/team.service.ts @@ -23,7 +23,7 @@ export const getAllTeamsWithPoints = async () => { } return result } catch (error) { - throw new Error("Failed to fetch teams. Please try again later."); + throw new Error("Failed to fetch teams. Please try again later: " + error); } } diff --git a/frontend/src/services/requests/teams.ts b/frontend/src/services/requests/teams.ts index 105d7457..6a6f17dc 100644 --- a/frontend/src/services/requests/teams.ts +++ b/frontend/src/services/requests/teams.ts @@ -53,7 +53,7 @@ export const getAllTeams = async () => { }; export const getAllTeamsWithPoints = async () => { - const response = await api.get("team/allWithPoints"); + const response = await api.get("team/teamsWithPoints"); return response.data.data; }; From c772638f8db3148d9fd4542fb92d64f01e97e546 Mon Sep 17 00:00:00 2001 From: Hugo Bergerat Date: Tue, 20 Aug 2024 16:47:52 +0200 Subject: [PATCH 15/15] Upgrade profile. --- backend/src/controllers/team.controller.ts | 2 - backend/src/routes/challenge.routes.ts | 4 +- backend/src/services/challenge.service.ts | 25 +++- backend/src/services/user.service.ts | 2 +- backend/src/utils/challenge.ts | 8 ++ frontend/src/components/profil/Profil.tsx | 136 ++++++++++++++++++- frontend/src/screens/Profil.tsx | 3 +- frontend/src/services/requests/challenges.ts | 5 + 8 files changed, 171 insertions(+), 14 deletions(-) diff --git a/backend/src/controllers/team.controller.ts b/backend/src/controllers/team.controller.ts index 6a1a38cd..541674ec 100644 --- a/backend/src/controllers/team.controller.ts +++ b/backend/src/controllers/team.controller.ts @@ -30,7 +30,6 @@ export const getAllTeamsWithPoints = async (req: Request, res: Response, next: N export const getTeam = async (req: Request, res: Response, next: NextFunction) => { const { id } = req.params; const idNumber = parseInt(id, 10); - console.log("pas censé 1") if (isNaN(idNumber)) return Error(res, { msg : 'Could not parse Id' }); try { @@ -57,7 +56,6 @@ export const createTeam = async (req: Request, res: Response, next: NextFunction export const deleteTeam = async (req: Request, res: Response, next: NextFunction) => { const { id } = req.params; const idNumber = parseInt(id, 10); - console.log("pas censé 2") if (isNaN(idNumber)) return Error(res, { msg : 'could not parse Id' }); try { diff --git a/backend/src/routes/challenge.routes.ts b/backend/src/routes/challenge.routes.ts index ae940dbb..a7b3b2b0 100644 --- a/backend/src/routes/challenge.routes.ts +++ b/backend/src/routes/challenge.routes.ts @@ -1,6 +1,6 @@ import express from 'express'; import * as fc from '../controllers/challenge.controller'; -import {isAdmin, isAdminAnim, isAdminCE} from '../middlewares/permissions'; +import {isAdmin, isAdminAnim, isAdminCE, isTokenValid} from '../middlewares/permissions'; const challengeRouter = express.Router(); @@ -13,7 +13,7 @@ challengeRouter.post('/getCompletedForTeam', isAdminAnim, fc.getCompletedChallen challengeRouter.post('/getCompletedForFaction', isAdminAnim, fc.getCompletedChallengeForFaction); challengeRouter.post('/getCompletedForStudent', isAdminAnim, fc.getCompletedChallengeForStudent); challengeRouter.post('/getAvailableForTeam', isAdminAnim, fc.getAvailableChallengeForTeam); -challengeRouter.post('/getAvailableForStudent', isAdminAnim, fc.getAvailableChallengeForStudent); +challengeRouter.post('/getAvailableForStudent', isTokenValid, fc.getAvailableChallengeForStudent); challengeRouter.post('/getAvailableForFaction', isAdminAnim, fc.getAvailableChallengeForFaction); challengeRouter.post('/unvalid', isAdminAnim, fc.unvalidChallenge); challengeRouter.post('/unvalidFree', isAdminAnim, fc.unvalidFreeChallenge); diff --git a/backend/src/services/challenge.service.ts b/backend/src/services/challenge.service.ts index 89687655..eb295cb2 100644 --- a/backend/src/services/challenge.service.ts +++ b/backend/src/services/challenge.service.ts @@ -19,7 +19,7 @@ import { getChallengeFromIds, getChallengesOf, getFactionFromTeam, getFactionFromUserId, - getTeamAndFactionFromUserId + getTeamAndFactionFromUserId, isCE } from "../utils/challenge"; import {NoFaction} from "../error/user"; @@ -133,12 +133,23 @@ export const getCompletedChallengesForCe = async (studentId: number): Promise => { const ids = await getTeamAndFactionFromUserId(studentId) - const completedChallengesIds = - [ - ...await getCompletedChallengesForStudent(studentId), - ...await getCompletedChallengesForTeam(ids.teamId), - ...await getCompletedChallengesForFaction(ids.factionId) - ] + //test if he is CE + let completedChallengesIds = [] + if(await isCE(studentId)) { + completedChallengesIds = + [ + ...await getCompletedChallengesForCe(studentId), + ...await getCompletedChallengesForTeam(ids.teamId), + ...await getCompletedChallengesForFaction(ids.factionId) + ] + } else { + completedChallengesIds = + [ + ...await getCompletedChallengesForStudent(studentId), + ...await getCompletedChallengesForTeam(ids.teamId), + ...await getCompletedChallengesForFaction(ids.factionId) + ] + } const allChallenges = await getAllChallenges() const allChallengesIds = allChallenges.map(chall => chall.id as number) const availableChallengeIds = allChallengesIds.filter(id => !completedChallengesIds.includes(id)); diff --git a/backend/src/services/user.service.ts b/backend/src/services/user.service.ts index d89c83fb..8fe78197 100644 --- a/backend/src/services/user.service.ts +++ b/backend/src/services/user.service.ts @@ -386,7 +386,7 @@ export async function getInfo(emails: string[]): Promise { }) */ -function isCe(user: User) { +export function isCe(user: User) { return user.permission === PermType.Student && user.team !== undefined } diff --git a/backend/src/utils/challenge.ts b/backend/src/utils/challenge.ts index b679e3d9..61ca2781 100644 --- a/backend/src/utils/challenge.ts +++ b/backend/src/utils/challenge.ts @@ -11,6 +11,7 @@ import { StudentTochallengeSchema, teamTochallenge, TeamTochallengeSchema } from "../schemas/challenge.schema"; +import {isCe} from "../services/user.service"; export async function getFactionFromTeam(userTeam: number): Promise { //get associated faction @@ -70,4 +71,11 @@ export async function getTeamAndFactionFromUserId(user: number): Promise<{teamId const userdb = await db.select().from(userSchema).where(eq(userSchema.id, user)) if(!userdb || userdb.length === 0) throw NoUser(user) return await getTeamAndFactionFromUser(userdb[0]) +} + +export async function isCE(studentId: number): Promise { + //get user + const userdb = await db.select().from(userSchema).where(eq(userSchema.id, studentId)) + if(!userdb || userdb.length === 0) throw NoUser(studentId) + return isCe(userdb[0]) } \ No newline at end of file diff --git a/frontend/src/components/profil/Profil.tsx b/frontend/src/components/profil/Profil.tsx index 944ec5f6..ec2fc879 100644 --- a/frontend/src/components/profil/Profil.tsx +++ b/frontend/src/components/profil/Profil.tsx @@ -3,11 +3,12 @@ import { getCurrentUser, updateUser } from '../../services/requests/users'; import { handleError } from '../utils/Submit'; import { ToastContainer, toast } from 'react-toastify'; import './Profil.css'; -import { Faction, Team, User } from '../../services/interfaces'; +import {ChallType, Faction, Team, User} from '../../services/interfaces'; import { getAllMembersTeam, getTeam } from '../../services/requests/teams'; import { getFaction } from '../../services/requests/factions'; import Select from "react-select"; import { Option } from "../../services/interfaces"; +import {getAvailableChallengeForUser} from "../../services/requests/challenges"; export const ProfilForm: React.FC = () => { const [firstName, setFirstName] = useState(''); @@ -209,4 +210,137 @@ export const TeamDisplay: React.FC = () => {
); +}; + +export const PossibleChallengeDisplay: React.FC = () => { + const [userTeam, setTeam] = useState(); + const [teamMembers, setTeamMembers] = useState([]); + const [userFaction, setFaction] = useState(); + const [permission, setPermission] = useState(""); + const [challenges, setChallenges] = useState([]) + const [challengesTeam, setChallengesTeam] = useState([]) + const [challengesFaction, setChallengesFaction] = useState([]) + + useEffect(() => { + const fetchUserTeamData = async () => { + try { + const currentUser = await getCurrentUser(); + const permission = currentUser.permission; + const team = await getTeam(currentUser.team_id); + setTeam(team); + if (team) { + setFaction(await getFaction(team.faction)); + setTeamMembers(await getAllMembersTeam(team.id)); + } + if(permission){ + setPermission(permission); + } + //get challenge + const challenges = await getAvailableChallengeForUser(currentUser.id as number) + console.log(challenges) + setChallenges(challenges.filter((chall: any) => chall.challType === ChallType.Student)) + setChallengesTeam(challenges.filter((chall: any) => chall.challType === ChallType.Team)) + setChallengesFaction(challenges.filter((chall: any) => chall.challType === ChallType.Faction)) + console.log(challenges) + } catch (error) { + console.error('Error fetching data:', error); + } + }; + fetchUserTeamData(); + }, []); + + return ( + <> +
+

Challenges Individuels

+
+ + + + + + + + + + {challenges?.length !== 0 ? ( + challenges?.map((chall: any) => ( + + + + + + )) + ) : ( + + + + )} + +
NOMDESCRIPTIONPOINTS
{chall.name}{chall.description}{chall.points}
Chargement...
+
+ +
+
+

Challenges d'équipes

+
+ + + + + + + + + + {challengesTeam?.length !== 0 ? ( + challengesTeam?.map((chall: any) => ( + + + + + + )) + ) : ( + + + + )} + +
NOMDESCRIPTIONPOINTS
{chall.name}{chall.description}{chall.points}
Chargement...
+
+ +
+
+

Challenges de factions

+
+ + + + + + + + + + {challengesFaction?.length !== 0 ? ( + challengesFaction?.map((chall: any) => ( + + + + + + )) + ) : ( + + + + )} + +
NOMDESCRIPTIONPOINTS
{chall.name}{chall.description}{chall.points}
Chargement...
+
+ +
+ + ); }; \ No newline at end of file diff --git a/frontend/src/screens/Profil.tsx b/frontend/src/screens/Profil.tsx index e9eddc5b..d34dd5f1 100644 --- a/frontend/src/screens/Profil.tsx +++ b/frontend/src/screens/Profil.tsx @@ -1,6 +1,6 @@ import { Navbar } from "../components/shared/Navbar" import { Section } from "../components/shared/Section" -import { ProfilForm, TeamDisplay } from "../components/profil/Profil" +import {PossibleChallengeDisplay, ProfilForm, TeamDisplay} from "../components/profil/Profil" import { useEffect } from "react"; import { getRole } from "../services/requests"; import { getCurrentUser } from "../services/requests/users"; @@ -29,6 +29,7 @@ export const Profil = () => {
+
) } diff --git a/frontend/src/services/requests/challenges.ts b/frontend/src/services/requests/challenges.ts index 21820eee..974bc3ec 100644 --- a/frontend/src/services/requests/challenges.ts +++ b/frontend/src/services/requests/challenges.ts @@ -14,6 +14,11 @@ export const getChallenges = async (type: ChallType, filter: Choice, associatedI return response.data.data; }; +export const getAvailableChallengeForUser = async (studentId: number) => { + const response = await api.post("challenge/getAvailableForStudent", { associatedId: studentId}); + return response.data.data; +}; + export const getAllFreeChallengesTexts = async (factionId: number) => { const response = await api.post("challenge/allFreeText", { factionId