diff --git a/README.md b/README.md index 79f84f1..0f29691 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Kildekoden er på engelsk. Kildekoden er på engelsk For at testene skal fungere, bruk node version >=22 + - `/` - `db/` database modul - `lib/` generell delt kode @@ -115,7 +116,7 @@ For å kjøre appen og migrere databasen, se [scripts](#database). ### Imports Autocomplete -[`christian-kohler.npm-intellisense`]() +[`christian-kohler.npm-intellisense`](https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense) ### Formatting and Linting @@ -226,12 +227,23 @@ Open the database in the drizzle studio interface: pnpm db:studio ``` -Seed the database with random, but deterministic values: +Seed the database with values: +for windows: ```sh pnpm db:seed ``` +for linux and mac: + +```sh +pnpm db seed:unix +``` + +```sh +pnpm db seed:unix +``` + ## Info -Tabellnavn er i *flertall* (users > user) +Tabellnavn er i _flertall_ (users > user) diff --git a/db/seeding/dbDiagramCode.txt b/db/seeding/dbDiagramCode.txt new file mode 100644 index 0000000..c7478aa --- /dev/null +++ b/db/seeding/dbDiagramCode.txt @@ -0,0 +1,250 @@ +Copy the code below into https://dbdiagram.io/d to map +out the different tables and their relations. + + +// Enums +Enum gender { + female + male + other +} + +Enum size { + small + medium + large +} + +Enum city { + Trondheim + Ås + Bergen + Tromsø +} + +/* + Tables +*/ + +Table users { + id int [pk, increment] + firstName varchar + lastName varchar + fieldOfStudyId int + accountNumber varchar [unique] // bankAccountNumber in code + personalEmail varchar [unique] + phoneNumber varchar [unique] +} + +Table teamUsers { + id int [pk] // also references users.id (see refs) + teamId int + username varchar [unique] +} + +Table assistantUsers { + id int [pk] // references users.id +} + +Table teams { + id int [pk, increment] + departmentId int + name varchar [unique] + email varchar [unique] + description text + shortDescription text + acceptApplication boolean + active boolean + deadline datetime +} + +Table departments { + id int [pk, increment] + city city +} + +Table fieldsOfStudy { + id int [pk, increment] + studyCode varchar [unique] + name varchar [unique] + departmentId int +} + +Table semesters { + id int [pk, increment] + lastSemesterId int // self reference -> semesters.id + semesterStartDate date + semesterEndDate date + recruitmentStartDate date + recruitmentEndDate date + departmentId int + name varchar +} + +Table applications { + id int [pk, increment] + firstname varchar + lastname varchar + gender gender + email varchar + fieldOfStudyId int + yearOfStudy int + phonenumber varchar + semester int + submitDate date +} + +Table teamApplications { + id int [pk] // part of composite PK + applicationParentId int [pk] // part of composite PK + teamId int + motivationText text + biography text + teamInterest boolean +} + +Table assistantApplications { + id int [pk] // references applications.id +} + +Table interviewSchemas { + id int [pk, increment] + jsonSchema json +} + +Table interviews { + id int [pk, increment] + applicationId int + interviewSchemaId int + interviewAnswers json + isCancelled boolean + plannedTime datetime + timeFinished datetime +} + +Table interviewHolders { + interviewId int [pk] + interviewHolderId int [pk] +} + +Table teamSemesterUser { + teamId int + semesterId int + teamUserId int +} + +Table schools { + id int [pk, increment] + departmentId int + name varchar + contactPersonName varchar + contactPersonPhoneNumber varchar + contactpersonEmail varchar + isInternational boolean +} + +Table schoolAssignments { + schoolId int + semesterId int [pk] + assistantUserId int [pk] +} + +Table meetings { + id int [pk, increment] + title varchar + description text + semesterId int + date date + timeStart time + timeEnd text + room text +} + +Table sponsors { + id int [pk, increment] + name varchar + homePageURL varchar + startTime datetime + endTime datetime + size size + spesificDepartmentId int +} + +Table expenses { + id int [pk, increment] + userId int + title varchar + description text + moneyAmount numeric(12,2) + accountNumber varchar + purchaseTime datetime + submitTime datetime + isAccepted boolean + handlingTime datetime +} + +/* + Relationships (foreign keys & references) +*/ + +// users +Ref: users.fieldOfStudyId > fieldsOfStudy.id +// teamUsers / users +Ref: teamUsers.id > users.id +Ref: teamUsers.teamId > teams.id + +// assistantUsers -> users +Ref: assistantUsers.id > users.id + +// teams -> departments +Ref: teams.departmentId > departments.id + +// fieldsOfStudy -> departments +Ref: fieldsOfStudy.departmentId > departments.id + +// departments -> semesters (department has many semesters) +Ref: semesters.departmentId > departments.id + +// semesters self reference +Ref: semesters.lastSemesterId > semesters.id + +// applications -> fieldsOfStudy, semesters +Ref: applications.fieldOfStudyId > fieldsOfStudy.id +Ref: applications.semester > semesters.id + +// teamApplications -> applications, teams +Ref: teamApplications.applicationParentId > applications.id +Ref: teamApplications.teamId > teams.id + +// assistantApplications has PK referencing applications.id +Ref: assistantApplications.id > applications.id + +// interviews -> assistantApplications, interviewSchemas +Ref: interviews.applicationId > assistantApplications.id +Ref: interviews.interviewSchemaId > interviewSchemas.id + +// interviewHolders -> interviews, teamUsers +Ref: interviewHolders.interviewId > interviews.id +Ref: interviewHolders.interviewHolderId > teamUsers.id + +// teamSemesterUser -> teams, semesters, teamUsers +Ref: teamSemesterUser.teamId > teams.id +Ref: teamSemesterUser.semesterId > semesters.id +Ref: teamSemesterUser.teamUserId > teamUsers.id + +// schools -> departments +Ref: schools.departmentId > departments.id + +// schoolAssignments -> schools, semesters, assistantUsers +Ref: schoolAssignments.schoolId > schools.id +Ref: schoolAssignments.semesterId > semesters.id +Ref: schoolAssignments.assistantUserId > assistantUsers.id + +// meetings -> semesters +Ref: meetings.semesterId > semesters.id + +// sponsors -> departments +Ref: sponsors.spesificDepartmentId > departments.id + +// expenses -> users +Ref: expenses.userId > users.id diff --git a/db/seeding/removeData.sql b/db/seeding/removeData.sql new file mode 100644 index 0000000..7c0f57c --- /dev/null +++ b/db/seeding/removeData.sql @@ -0,0 +1,25 @@ +BEGIN; + +TRUNCATE TABLE + "mainSchema"."interviewHolders", + "mainSchema"."teamSemesterUser", + "mainSchema"."schoolAssignments", + "mainSchema"."interviews", + "mainSchema"."assistantApplications", + "mainSchema"."teamApplications", + "mainSchema"."applications", + "mainSchema"."assistantUsers", + "mainSchema"."teamUsers", + "mainSchema"."expenses", + "mainSchema"."sponsors", + "mainSchema"."users", + "mainSchema"."meetings", + "mainSchema"."schools", + "mainSchema"."semesters", + "mainSchema"."teams", + "mainSchema"."fieldsOfStudy", + "mainSchema"."departments", + "mainSchema"."interviewSchemas" +RESTART IDENTITY CASCADE; + +COMMIT; diff --git a/db/seeding/seed.sql b/db/seeding/seed.sql index e69de29..0a57afa 100644 --- a/db/seeding/seed.sql +++ b/db/seeding/seed.sql @@ -0,0 +1,479 @@ +BEGIN; + +-- Departments +INSERT INTO "mainSchema"."departments" ("id", "city") VALUES + (1, 'Trondheim'), + (2, 'Bergen') +ON CONFLICT ("id") DO NOTHING; + +-- Fields of study +INSERT INTO "mainSchema"."fieldsOfStudy" ("id", "studyCode", "name", "departmentId") VALUES + (1, 'MTKJ', 'Mechanical Engineering', 1), + (2, 'INF101', 'Computer Science', 1), + (3, 'BIO200', 'Marine Biology', 2) +ON CONFLICT ("id") DO NOTHING; +/* */ +-- Teams +INSERT INTO "mainSchema"."teams" + ("id", "departmentId", "name", "email", "description", "shortDescription", "acceptApplication", "active", "deadline") +VALUES + ( + 1, + 1, + 'Logistics Trondheim', + 'logistics.trondheim@vektor.no', + 'Handles classroom logistics in Trondheim.', + 'Logistics Trondheim', + true, + true, + '2023-12-15 23:59:00' + ), + ( + 2, + 1, + 'Public Relations Trondheim', + 'pr.trondheim@vektor.no', + 'Showcases Vektor at events and online.', + 'PR Trondheim', + true, + true, + '2023-12-20 23:59:00' + ), + ( + 3, + 2, + 'Recruitment Bergen', + 'recruitment.bergen@vektor.no', + 'Coordinates mentor recruitment in Bergen.', + 'Recruitment Bergen', + true, + false, + '2024-05-01 23:59:00' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Semesters +INSERT INTO "mainSchema"."semesters" + ( + "id", + "lastSemesterId", + "semesterStartDate", + "semesterEndDate", + "recruitmentStartDate", + "recruitmentEndDate", + "departmentId", + "name" + ) +VALUES + ( + 1, + NULL, + '2024-01-08', + '2024-06-15', + '2023-11-01', + '2024-01-01', + 1, + 'Spring 2024 Trondheim' + ), + ( + 2, + 1, + '2024-08-19', + '2024-12-18', + '2024-04-15', + '2024-06-01', + 1, + 'Fall 2024 Trondheim' + ), + ( + 3, + NULL, + '2024-01-10', + '2024-06-20', + '2023-11-15', + '2024-01-05', + 2, + 'Spring 2024 Bergen' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Meetings +INSERT INTO "mainSchema"."meetings" + ("id", "title", "description", "semesterId", "date", "timeStart", "timeEnd", "room") +VALUES + ( + 1, + 'Mentor Kickoff', + 'Kickoff for returning and new mentors.', + 1, + '2024-01-15', + '17:00:00', + '19:00', + 'Gløshaugen A1' + ), + ( + 2, + 'Recruitment Retrospective', + 'Wrap-up for the fall recruitment.', + 2, + '2024-09-05', + '18:00:00', + '20:00', + 'IT-bygget 42' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Schools +INSERT INTO "mainSchema"."schools" + ( + "id", + "departmentId", + "name", + "contactPersonName", + "contactPersonPhoneNumber", + "contactpersonEmail", + "isInternational" + ) +VALUES + ( + 1, + 1, + 'Charlottenlund ungdomsskole', + 'Ingrid Lien', + '93000001', + 'ingrid.lien@charlottenlund.no', + false + ), + ( + 2, + 2, + 'International School Bergen', + 'Paul Jensen', + '93000002', + 'paul.jensen@isb.no', + true + ) +ON CONFLICT ("id") DO NOTHING; + +-- Users +INSERT INTO "mainSchema"."users" + ( + "id", + "firstName", + "lastName", + "fieldOfStudyId", + "accountNumber", + "personalEmail", + "phoneNumber" + ) +VALUES + ( + 1, + 'Frida', + 'Larsen', + 1, + '12345678901', + 'frida.larsen@example.com', + '40000001' + ), + ( + 2, + 'Eirik', + 'Sund', + 2, + '23456789012', + 'eirik.sund@example.com', + '40000002' + ), + ( + 3, + 'Maja', + 'Solheim', + 3, + '34567890123', + 'maja.solheim@example.com', + '40000003' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Team users +INSERT INTO "mainSchema"."teamUsers" ("id", "teamId", "username") VALUES + (1, 1, 'frida.l'), + (2, 2, 'eirik.s'), + (3, 3, 'maja.s') +ON CONFLICT ("id") DO NOTHING; + +-- Assistant users +INSERT INTO "mainSchema"."assistantUsers" ("id") VALUES + (2), + (3) +ON CONFLICT ("id") DO NOTHING; + +-- Applications +INSERT INTO "mainSchema"."applications" + ( + "id", + "firstname", + "lastname", + "gender", + "email", + "fieldOfStudyId", + "yearOfStudy", + "phonenumber", + "submitDate" + ) +VALUES + ( + 1, + 'Ola', + 'Nordmann', + 'male', + 'ola.nordmann@example.com', + 1, + 2, + '90000001', + '2023-11-25' + ), + ( + 2, + 'Kari', + 'Hansen', + 'female', + 'kari.hansen@example.com', + 2, + 1, + '90000002', + '2023-11-28' + ), + ( + 3, + 'Noor', + 'Ali', + 'other', + 'noor.ali@example.com', + 3, + 3, + '90000003', + '2023-12-02' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Team applications +INSERT INTO "mainSchema"."teamApplications" + ( + "id", + "applicationParentId", + "teamId", + "motivationText", + "biography", + "teamInterest" + ) +VALUES + ( + 1, + 1, + 1, + 'I love planning lessons and logistics.', + 'Second-year mechanical engineering student.', + true + ), + ( + 2, + 2, + 2, + 'I want to tell new students about Vektor.', + 'First-year computer science student.', + true + ), + ( + 3, + 3, + 3, + 'I am moving to Bergen and want to stay involved.', + 'Third-year marine biology student.', + false + ) +ON CONFLICT ("id", "applicationParentId") DO NOTHING; + +-- Assistant applications +INSERT INTO "mainSchema"."assistantApplications" ("id") VALUES + (1), + (2) +ON CONFLICT ("id") DO NOTHING; + +-- Interview schemas +INSERT INTO "mainSchema"."interviewSchemas" ("id", "jsonSchema") VALUES + ( + 1, + '{"title":"Assistant Interview","type":"object","properties":{"motivation":{"type":"string"}}}'::json + ), + ( + 2, + '{"title":"Follow-up Interview","type":"object","properties":{"evaluation":{"type":"number"}}}'::json + ) +ON CONFLICT ("id") DO NOTHING; + +-- Interviews +INSERT INTO "mainSchema"."interviews" + ( + "id", + "applicationId", + "interviewSchemaId", + "interviewAnswers", + "isCancelled", + "plannedTime", + "timeFinished" + ) +VALUES + ( + 1, + 1, + 1, + '{"motivation":"Help pupils learn math","score":5}'::json, + false, + '2024-01-20 10:00:00', + '2024-01-20 11:00:00' + ), + ( + 2, + 2, + 2, + '{"evaluation":3,"notes":"Needs more classroom experience"}'::json, + false, + '2024-01-22 14:00:00', + '2024-01-22 15:00:00' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Interview holders +INSERT INTO "mainSchema"."interviewHolders" ("integerId", "interviewHolderId") VALUES + (1, 1), + (2, 2) +ON CONFLICT ("integerId", "interviewHolderId") DO NOTHING; + +-- Expenses +INSERT INTO "mainSchema"."expenses" + ( + "id", + "userId", + "title", + "description", + "moneyAmount", + "accountNumber", + "purchaseTime", + "submitTime", + "isAccepted", + "handlingTime" + ) +VALUES + ( + 1, + 1, + 'Whiteboard markers', + 'Marker pack for school visit', + 250.00, + '50123456789', + '2024-02-01 12:00:00', + '2024-02-02 09:00:00', + true, + '2024-02-05 10:00:00' + ), + ( + 2, + 2, + 'Bus tickets', + 'Travel to International School Bergen', + 180.50, + '50123456780', + '2024-02-10 08:15:00', + '2024-02-10 20:00:00', + false, + '2024-02-12 09:30:00' + ) +ON CONFLICT ("id") DO NOTHING; + +-- Sponsors +INSERT INTO "mainSchema"."sponsors" + ( + "id", + "name", + "homePageURL", + "startTime", + "endTime", + "size", + "spesificDepartmentId" + ) +VALUES + ( + 1, + 'TechCorp', + 'https://techcorp.example.com', + '2024-01-01 00:00:00', + '2024-12-31 23:59:00', + 'medium', + 1 + ), + ( + 2, + 'EduFuture', + 'https://edufuture.example.com', + '2024-03-01 00:00:00', + NULL, + 'small', + NULL + ) +ON CONFLICT ("id") DO NOTHING; + +-- School assignments +INSERT INTO "mainSchema"."schoolAssignments" ("schoolId", "semesterId", "userId") VALUES + (1, 1, 2), + (2, 3, 3) +ON CONFLICT ("semesterId", "userId") DO NOTHING; + +-- Team members per semester +INSERT INTO "mainSchema"."teamSemesterUser" ("teamId", "semesterId", "teamUserId") +SELECT 1, 1, 1 +WHERE NOT EXISTS ( + SELECT 1 + FROM "mainSchema"."teamSemesterUser" + WHERE "teamId" = 1 + AND "semesterId" = 1 + AND "teamUserId" = 1 +); + +INSERT INTO "mainSchema"."teamSemesterUser" ("teamId", "semesterId", "teamUserId") +SELECT 2, 2, 2 +WHERE NOT EXISTS ( + SELECT 1 + FROM "mainSchema"."teamSemesterUser" + WHERE "teamId" = 2 + AND "semesterId" = 2 + AND "teamUserId" = 2 +); + +INSERT INTO "mainSchema"."teamSemesterUser" ("teamId", "semesterId", "teamUserId") +SELECT 3, 3, 3 +WHERE NOT EXISTS ( + SELECT 1 + FROM "mainSchema"."teamSemesterUser" + WHERE "teamId" = 3 + AND "semesterId" = 3 + AND "teamUserId" = 3 +); + +-- Align sequences so future inserts can rely on defaults +SELECT setval('"mainSchema"."departments_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."departments"), 0), true); +SELECT setval('"mainSchema"."fieldsOfStudy_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."fieldsOfStudy"), 0), true); +SELECT setval('"mainSchema"."teams_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."teams"), 0), true); +SELECT setval('"mainSchema"."semesters_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."semesters"), 0), true); +SELECT setval('"mainSchema"."meetings_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."meetings"), 0), true); +SELECT setval('"mainSchema"."schools_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."schools"), 0), true); +SELECT setval('"mainSchema"."users_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."users"), 0), true); +SELECT setval('"mainSchema"."applications_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."applications"), 0), true); +SELECT setval('"mainSchema"."teamApplications_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."teamApplications"), 0), true); +SELECT setval('"mainSchema"."interviewSchemas_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."interviewSchemas"), 0), true); +SELECT setval('"mainSchema"."interviews_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."interviews"), 0), true); +SELECT setval('"mainSchema"."expenses_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."expenses"), 0), true); +SELECT setval('"mainSchema"."sponsors_id_seq"', COALESCE((SELECT MAX("id") FROM "mainSchema"."sponsors"), 0), true); + +COMMIT; diff --git a/db/seeding/seeding-tables.ts b/db/seeding/seeding-tables.ts index 0b3d088..e7340c5 100644 --- a/db/seeding/seeding-tables.ts +++ b/db/seeding/seeding-tables.ts @@ -1,13 +1,21 @@ +import { applicationsTable } from "@/db/tables/applications"; +import { departmentsTable } from "@/db/tables/departments"; +import { expensesTable } from "@/db/tables/expenses"; +import { fieldsOfStudyTable } from "@/db/tables/fields-of-study"; +import { teamsTable } from "@/db/tables/teams"; +import { usersTable } from "@/db/tables/users"; + export const seedingTables = { - //departmentsTable, - //fieldsOfStudyTable, - //teamsTable, - //usersTable, + departmentsTable, + fieldsOfStudyTable, + teamsTable, + usersTable, + // meetings, //teamUsersTable, these two tables dont work currently //assistantUsersTable, //teamApplicationsTable, - //expensesTable, - //applicationsTable, + expensesTable, + applicationsTable, // meetingsTable, // schoolsTable }; diff --git a/db/tables/applications.ts b/db/tables/applications.ts index f8a39dc..f60dfbc 100644 --- a/db/tables/applications.ts +++ b/db/tables/applications.ts @@ -12,7 +12,6 @@ import { import { teamsTable } from "@/db/tables/teams"; import { fieldsOfStudyTable } from "./fields-of-study"; import { interviewsTable } from "./interviews"; -import { semestersTable } from "./semesters"; export const gendersEnum = mainSchema.enum("gender", [ "female", @@ -31,9 +30,6 @@ export const applicationsTable = mainSchema.table("applications", { .references(() => fieldsOfStudyTable.id), yearOfStudy: integer("yearOfStudy").notNull(), phonenumber: text("phonenumber").notNull(), - semester: integer("semester") - .notNull() - .references(() => semestersTable.id), submitDate: date("submitDate", { mode: "date" }).defaultNow().notNull(), }); @@ -44,10 +40,6 @@ export const applicationsRelations = relations( fields: [applicationsTable.fieldOfStudyId], references: [fieldsOfStudyTable.id], }), - semesters: one(semestersTable, { - fields: [applicationsTable.semester], - references: [semestersTable.id], - }), assistantApplication: one(assistantApplicationsTable, { fields: [applicationsTable.id], references: [assistantApplicationsTable.id], @@ -105,6 +97,9 @@ export const assistantApplicationsRelations = relations( fields: [assistantApplicationsTable.id], references: [applicationsTable.id], }), - interview: one(interviewsTable), + interview: one(interviewsTable, { + fields: [assistantApplicationsTable.id], + references: [interviewsTable.applicationId], + }), }), ); diff --git a/db/tables/assistant-semesters.ts b/db/tables/assistant-semesters.ts deleted file mode 100644 index 74855e5..0000000 --- a/db/tables/assistant-semesters.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { relations } from "drizzle-orm"; -import { boolean, integer, primaryKey } from "drizzle-orm/pg-core"; -import { mainSchema } from "./schema"; -import { semestersTable } from "./semesters"; -import { assistantUsersTable } from "./users"; - -export const assistantSemestersTable = mainSchema.table( - "assistantSemesters", - { - assistantId: integer("semesterId") - .references(() => assistantUsersTable.id) - .notNull(), - semesterId: integer("assistantId") - .references(() => semestersTable.id) - .notNull(), - isSubstitute: boolean("isSubstitute").notNull(), - }, - (table) => ({ - pk: primaryKey({ - columns: [table.assistantId, table.semesterId], - }), - }), -); - -export const assistantSemestersRelations = relations( - assistantSemestersTable, - ({ many }) => ({ - assistant: many(assistantUsersTable), - semester: many(semestersTable), - }), -); diff --git a/db/tables/school-semester.ts b/db/tables/school-semester.ts deleted file mode 100644 index 20811e2..0000000 --- a/db/tables/school-semester.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { integer } from "drizzle-orm/pg-core"; -import { mainSchema } from "./schema"; -import { schoolsTable } from "./schools"; -import { semestersTable } from "./semesters"; - -export const schoolSemesterTable = mainSchema.table("schoolSemesters", { - capacity: integer("capacity").notNull(), - schoolId: integer("schoolId") - .notNull() - .references(() => schoolsTable.id), - semesterId: integer("semesterId") - .notNull() - .references(() => semestersTable.id), -}); diff --git a/db/tables/semesters.ts b/db/tables/semesters.ts index d22cd64..f8d6bfb 100644 --- a/db/tables/semesters.ts +++ b/db/tables/semesters.ts @@ -6,7 +6,6 @@ import { serial, text, } from "drizzle-orm/pg-core"; -import { applicationsTable } from "./applications"; import { departmentsTable } from "./departments"; import { meetingsTable } from "./meetings"; import { mainSchema } from "./schema"; @@ -45,7 +44,6 @@ export const semestersRelations = relations( }), schoolAssistants: many(schoolAssignmentsTable), teamUsers: many(teamSemesterUsersTable), - applications: many(applicationsTable), meetings: many(meetingsTable), }), ); diff --git a/package.json b/package.json index f5249fe..4be14f5 100644 --- a/package.json +++ b/package.json @@ -1,56 +1,59 @@ { - "name": "vektor-api", - "version": "0.0.1", - "description": "", - "main": "./src/main.ts", - "type": "module", - "scripts": { - "dev:once": "tsx ./src/main.ts", - "dev": "tsx watch ./src/main.ts", - "build": "tsc --project ./tsconfig.json && tsc-alias --project ./tsconfig.json --resolve-full-paths", - "start": "node ./build/src/main.js", - "prod": "pnpm build && pnpm start", - "test": "tsc --noEmit && node --import tsx --test --test-force-exit ./src/test/*.ts", - "format": "biome format --write", - "lint": "biome lint --write", - "check": "biome check --write", - "db:generate": "drizzle-kit generate --config=db/config/drizzle.config.ts", - "db:migrate": "drizzle-kit migrate --config=db/config/drizzle.config.ts", - "db:studio": "drizzle-kit studio --config=db/config/drizzle.config.ts", - "db:seed": "tsx ./db/seeding/seeding.ts", - "docs:generate": "tsx ./openapi/generate-document.ts" - }, - "license": "ISC", - "dependencies": { - "cors": "^2.8.5", - "dotenv": "^16.4.7", - "drizzle-orm": "^0.33.0", - "drizzle-seed": "^0.3.1", - "drizzle-zod": "^0.5.1", - "express": "^5.1.0", - "express-zod-safe": "^1.3.3", - "pg": "^8.14.1", - "swagger-jsdoc": "^6.2.8", - "validator": "^13.15.0", - "zod": "^3.24.2", - "zod-openapi": "^3.3.0", - "zod-validation-error": "^3.4.0" - }, - "devDependencies": { - "@biomejs/biome": "1.9.3", - "@types/cors": "^2.8.17", - "@types/express": "^4.17.21", - "@types/node": "^22.14.0", - "@types/pg": "^8.11.11", - "@types/supertest": "^6.0.3", - "@types/swagger-jsdoc": "^6.0.4", - "@types/validator": "^13.12.3", - "drizzle-kit": "^0.24.2", - "supertest": "^7.1.0", - "tsc-alias": "^1.8.13", - "tsx": "^4.19.3", - "typescript": "^5.8.2", - "yaml": "^2.7.1" - }, - "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b" + "name": "vektor-api", + "version": "0.0.1", + "description": "", + "main": "./src/main.ts", + "type": "module", + "scripts": { + "dev:once": "tsx ./src/main.ts", + "dev": "tsx watch ./src/main.ts", + "build": "tsc --project ./tsconfig.json && tsc-alias --project ./tsconfig.json --resolve-full-paths", + "start": "node ./build/src/main.js", + "prod": "pnpm build && pnpm start", + "test": "tsc --noEmit && node --import tsx --test --test-force-exit ./src/test/*.ts", + "format": "biome format --write", + "lint": "biome lint --write", + "check": "biome check --write", + "db:generate": "drizzle-kit generate --config=db/config/drizzle.config.ts", + "db:migrate": "drizzle-kit migrate --config=db/config/drizzle.config.ts", + "db:studio": "drizzle-kit studio --config=db/config/drizzle.config.ts", + "db:seed": "powershell -NoProfile -Command \"Get-Content db\\\\seeding\\\\seed.sql | docker compose exec -T db psql -U postgres -d vektorPostgres\"", + "db:seed:unix": "sudo docker compose exec -T db psql -U postgres -d vektorPostgres < db/seeding/seed.sql", + "db:unseed": "powershell -NoProfile -Command \"Get-Content db\\\\seeding\\\\removeData.sql | docker compose exec -T db psql -U postgres -d vektorPostgres\"", + "db:unseed:unix": "sudo docker compose exec -T db psql -U postgres -d vektorPostgres < db/seeding/removeData.sql", + "docs:generate": "tsx ./openapi/generate-document.ts" + }, + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.4.7", + "drizzle-orm": "^0.33.0", + "drizzle-seed": "^0.3.1", + "drizzle-zod": "^0.5.1", + "express": "^5.1.0", + "express-zod-safe": "^1.3.3", + "pg": "^8.14.1", + "swagger-jsdoc": "^6.2.8", + "validator": "^13.15.0", + "zod": "^3.24.2", + "zod-openapi": "^3.3.0", + "zod-validation-error": "^3.4.0" + }, + "devDependencies": { + "@biomejs/biome": "1.9.3", + "@types/cors": "^2.8.17", + "@types/express": "^4.17.21", + "@types/node": "^22.14.0", + "@types/pg": "^8.11.11", + "@types/supertest": "^6.0.3", + "@types/swagger-jsdoc": "^6.0.4", + "@types/validator": "^13.12.3", + "drizzle-kit": "^0.24.2", + "supertest": "^7.1.0", + "tsc-alias": "^1.8.13", + "tsx": "^4.19.3", + "typescript": "^5.8.2", + "yaml": "^2.7.1" + }, + "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b" } diff --git a/src/db-access/applications.ts b/src/db-access/applications.ts index 328a731..2fa95b2 100644 --- a/src/db-access/applications.ts +++ b/src/db-access/applications.ts @@ -37,7 +37,6 @@ export const selectTeamApplications = async ( motivationText: teamApplicationsTable.motivationText, biography: teamApplicationsTable.biography, teamInterest: teamApplicationsTable.teamInterest, - semester: applicationsTable.semester, submitDate: applicationsTable.submitDate, }) .from(teamApplicationsTable) @@ -72,7 +71,6 @@ export const selectTeamApplicationsByTeamId = async ( motivationText: teamApplicationsTable.motivationText, biography: teamApplicationsTable.biography, teamInterest: teamApplicationsTable.teamInterest, - semester: applicationsTable.semester, submitDate: applicationsTable.submitDate, }) .from(teamApplicationsTable) @@ -108,7 +106,6 @@ export const selectTeamApplicationsById = async ( motivationText: teamApplicationsTable.motivationText, biography: teamApplicationsTable.biography, teamInterest: teamApplicationsTable.teamInterest, - semester: applicationsTable.semester, submitDate: applicationsTable.submitDate, }) .from(teamApplicationsTable) @@ -141,7 +138,6 @@ export async function insertTeamApplication( fieldOfStudyId: teamApplication.fieldOfStudyId, yearOfStudy: teamApplication.yearOfStudy, phonenumber: teamApplication.phonenumber, - semester: teamApplication.semester, }) .returning(); const newApplicationId = newApplication[0].id; diff --git a/src/request-handling/applications.ts b/src/request-handling/applications.ts index a3df681..101c6e2 100644 --- a/src/request-handling/applications.ts +++ b/src/request-handling/applications.ts @@ -37,7 +37,6 @@ export const applicationParser = z .string() .regex(/^\d{8}$/, "Phone number must be 8 digits") .describe("The phonenumber of the user applying for a team"), - semester: serialIdParser.describe("The semester the application is for"), }) .strict();