From 3f51e4292996af3a4e55e495391356567feb02f7 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 16:52:43 +0200 Subject: [PATCH 1/9] feat: :sparkles: made semesterId and assistantUserId notNull in schoolsemesterassistant table vf-325 --- db/tables/school-semester-assistant.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/tables/school-semester-assistant.ts b/db/tables/school-semester-assistant.ts index 5df90bd..263c921 100644 --- a/db/tables/school-semester-assistant.ts +++ b/db/tables/school-semester-assistant.ts @@ -9,8 +9,8 @@ export const schoolSemesterAssistantsTable = mainSchema.table( "schoolSemesterAssistant", { schoolId: integer("schoolId").references(() => schoolsTable.id), - semesterId: integer("semesterId").references(() => semestersTable.id), - assistantUserId: integer("userId").references(() => assistantUsersTable.id), + semesterId: integer("semesterId").references(() => semestersTable.id).notNull(), + assistantUserId: integer("userId").references(() => assistantUsersTable.id).notNull(), }, ); From 0c6e9c38eb6b0c1150563c4bf48eeec3a4c795b0 Mon Sep 17 00:00:00 2001 From: TobiasH05 <47815590+TobiasH05@users.noreply.github.com> Date: Wed, 8 Oct 2025 18:34:31 +0200 Subject: [PATCH 2/9] Vf 295 lag et kall som lager en team application fra en assistant (#43) * feat: :sparkles: start making call to translate from assistant application to team application * made composite key for team application table, issue: vf-319 * fix: fix following faults from issue vf-319 (composite key in teamapplication table) vf-319, vf-295 * fix: :bug: fixed following error * fix: :bug: fixed issue that we had 2 id fields * feat: create parser for teaminterest vf-295 * fix: fix small writing error vf-295 * fix: fix small error vf-295 * style: :art: pnpm check * feat: :sparkles: made function that creates application use z.infer as input type * feat: :art: pnpm check --------- Co-authored-by: solvhold --- db/tables/applications.ts | 37 +++++++++++------ src/db-access/applications.ts | 57 +++++++++++++++++++++++---- src/request-handling/applications.ts | 8 ++++ src/response-handling/applications.ts | 5 ++- src/routers/applications.ts | 55 +++++++++++++++++++++++++- 5 files changed, 141 insertions(+), 21 deletions(-) diff --git a/db/tables/applications.ts b/db/tables/applications.ts index b375563..264868c 100644 --- a/db/tables/applications.ts +++ b/db/tables/applications.ts @@ -1,6 +1,13 @@ import { mainSchema } from "@/db/tables/schema"; import { relations } from "drizzle-orm"; -import { date, integer, serial, text } from "drizzle-orm/pg-core"; +import { + boolean, + date, + integer, + primaryKey, + serial, + text, +} from "drizzle-orm/pg-core"; import { teamsTable } from "@/db/tables/teams"; import { fieldsOfStudyTable } from "./fields-of-study"; @@ -42,16 +49,24 @@ export const applicationsRelations = relations( }), ); -export const teamApplicationsTable = mainSchema.table("teamApplications", { - id: integer("id") - .primaryKey() - .references(() => applicationsTable.id), - teamId: integer("teamId") - .notNull() - .references(() => teamsTable.id), - motivationText: text("motivationText").notNull(), - biography: text("biography").notNull(), -}); +export const teamApplicationsTable = mainSchema.table( + "teamApplications", + { + id: serial("id"), + applicationParentId: integer("applicationParentId").references( + () => applicationsTable.id, + ), + teamId: integer("teamId") + .notNull() + .references(() => teamsTable.id), + motivationText: text("motivationText"), + biography: text("biography"), + teamInterest: boolean("teamInterest").notNull(), + }, + (table) => ({ + primaryKey: primaryKey({ columns: [table.id, table.applicationParentId] }), + }), +); export const teamApplicationsRelations = relations( teamApplicationsTable, diff --git a/src/db-access/applications.ts b/src/db-access/applications.ts index b2a7893..2fa95b2 100644 --- a/src/db-access/applications.ts +++ b/src/db-access/applications.ts @@ -3,10 +3,11 @@ import { applicationsTable, teamApplicationsTable, } from "@/db/tables/applications"; -import type { OrmResult } from "@/src/error/orm-error"; +import { type OrmResult, ormError } from "@/src/error/orm-error"; import type { NewApplication, NewTeamApplication, + NewTeamInterestApplication, } from "@/src/request-handling/applications"; import type { QueryParameters } from "@/src/request-handling/common"; import type { @@ -14,7 +15,7 @@ import type { TeamApplication, TeamKey, } from "@/src/response-handling/applications"; -import { eq, inArray } from "drizzle-orm"; +import { and, eq, inArray } from "drizzle-orm"; import { newDatabaseTransaction } from "./common"; export const selectTeamApplications = async ( @@ -24,6 +25,7 @@ export const selectTeamApplications = async ( const teamApplications = await tx .select({ id: applicationsTable.id, + applicationParentId: teamApplicationsTable.applicationParentId, teamId: teamApplicationsTable.teamId, firstName: applicationsTable.firstName, lastName: applicationsTable.lastName, @@ -34,12 +36,13 @@ export const selectTeamApplications = async ( phonenumber: applicationsTable.phonenumber, motivationText: teamApplicationsTable.motivationText, biography: teamApplicationsTable.biography, + teamInterest: teamApplicationsTable.teamInterest, submitDate: applicationsTable.submitDate, }) .from(teamApplicationsTable) .innerJoin( applicationsTable, - eq(teamApplicationsTable.id, applicationsTable.id), + eq(teamApplicationsTable.applicationParentId, applicationsTable.id), ) .limit(parameters.limit) .offset(parameters.offset); @@ -56,6 +59,7 @@ export const selectTeamApplicationsByTeamId = async ( const selectResult = await tx .select({ id: applicationsTable.id, + applicationParentId: teamApplicationsTable.applicationParentId, teamId: teamApplicationsTable.teamId, firstName: applicationsTable.firstName, lastName: applicationsTable.lastName, @@ -66,13 +70,14 @@ export const selectTeamApplicationsByTeamId = async ( phonenumber: applicationsTable.phonenumber, motivationText: teamApplicationsTable.motivationText, biography: teamApplicationsTable.biography, + teamInterest: teamApplicationsTable.teamInterest, submitDate: applicationsTable.submitDate, }) .from(teamApplicationsTable) .where(inArray(teamApplicationsTable.id, teamId)) .innerJoin( applicationsTable, - eq(teamApplicationsTable.id, applicationsTable.id), + eq(teamApplicationsTable.applicationParentId, applicationsTable.id), ) .limit(parameters.limit) .offset(parameters.offset); @@ -83,11 +88,13 @@ export const selectTeamApplicationsByTeamId = async ( export const selectTeamApplicationsById = async ( applicationIds: ApplicationKey[], + teamApplicationIds: number[], ): Promise> => { return await newDatabaseTransaction(database, async (tx) => { const selectResult = await tx .select({ - id: applicationsTable.id, + id: teamApplicationsTable.id, + applicationParentId: teamApplicationsTable.applicationParentId, teamId: teamApplicationsTable.teamId, firstName: applicationsTable.firstName, lastName: applicationsTable.lastName, @@ -98,13 +105,19 @@ export const selectTeamApplicationsById = async ( phonenumber: applicationsTable.phonenumber, motivationText: teamApplicationsTable.motivationText, biography: teamApplicationsTable.biography, + teamInterest: teamApplicationsTable.teamInterest, submitDate: applicationsTable.submitDate, }) .from(teamApplicationsTable) - .where(inArray(teamApplicationsTable.id, applicationIds)) + .where( + and( + inArray(teamApplicationsTable.applicationParentId, applicationIds), + inArray(teamApplicationsTable.id, teamApplicationIds), + ), + ) .innerJoin( applicationsTable, - eq(teamApplicationsTable.id, applicationsTable.id), + eq(teamApplicationsTable.applicationParentId, applicationsTable.id), ); return selectResult; @@ -132,10 +145,11 @@ export async function insertTeamApplication( const newTeamApplicationResult = await tx .insert(teamApplicationsTable) .values({ - id: newApplicationId, + applicationParentId: newApplicationId, teamId: teamApplication.teamId, motivationText: teamApplication.motivationText, biography: teamApplication.biography, + teamInterest: teamApplication.teamInterest, }) .returning(); @@ -145,3 +159,30 @@ export async function insertTeamApplication( }; }); } + +export async function createTeamApplicationFromAssistantApplication( + teamInterestApplication: NewTeamInterestApplication, +): Promise> { + return await newDatabaseTransaction(database, async (tx) => { + const newTeamApplicationResult = await tx + .insert(teamApplicationsTable) + .values({ + applicationParentId: teamInterestApplication.applicationParentId, + teamId: teamInterestApplication.teamId, + motivationText: teamInterestApplication.motivationText, + biography: teamInterestApplication.biography, + teamInterest: true, + }) + .returning(); + + const teamApplicationResult = await selectTeamApplicationsById( + [teamInterestApplication.applicationParentId], + [newTeamApplicationResult[0].id], + ); + if (!teamApplicationResult.success) { + throw ormError("Transaction failed", teamApplicationResult.error); + } + + return teamApplicationResult.data; + }); +} diff --git a/src/request-handling/applications.ts b/src/request-handling/applications.ts index 57e19a7..101c6e2 100644 --- a/src/request-handling/applications.ts +++ b/src/request-handling/applications.ts @@ -86,8 +86,16 @@ export const assistantApplicationToInsertParser = assistantApplicationParser .readonly(), ); +export const teamInterestParser = z.object({ + applicationParentId: serialIdParser, + teamId: teamApplicationParser.shape.teamId, + biography: teamApplicationParser.shape.biography.nullable(), + motivationText: teamApplicationParser.shape.motivationText.nullable(), +}); + export type NewApplication = z.infer; export type NewTeamApplication = z.infer; export type NewAssistantApplication = z.infer< typeof assistantApplicationToInsertParser >; +export type NewTeamInterestApplication = z.infer; diff --git a/src/response-handling/applications.ts b/src/response-handling/applications.ts index fa09a77..517a677 100644 --- a/src/response-handling/applications.ts +++ b/src/response-handling/applications.ts @@ -21,5 +21,8 @@ export const teamApplicationSelectSchema = createSelectSchema( .readonly(); export type TeamApplication = z.infer; -export type TeamApplicationKey = TeamApplication["id"]; +export type TeamApplicationKey = { + id: TeamApplication["id"]; + applicationParentId: TeamApplication["applicationParentId"]; +}; export type TeamKey = TeamApplication["teamId"]; diff --git a/src/routers/applications.ts b/src/routers/applications.ts index d2a2c33..e517927 100644 --- a/src/routers/applications.ts +++ b/src/routers/applications.ts @@ -1,10 +1,14 @@ import { + createTeamApplicationFromAssistantApplication, insertTeamApplication, selectTeamApplications, selectTeamApplicationsByTeamId, } from "@/src/db-access/applications"; import { clientError } from "@/src/error/http-errors"; -import { teamApplicationToInsertParser } from "@/src/request-handling/applications"; +import { + teamApplicationToInsertParser, + teamInterestParser, +} from "@/src/request-handling/applications"; import { toListQueryParser, toSerialIdParser, @@ -147,3 +151,52 @@ teamApplicationRouter.post("/", async (req, res, next) => { } res.status(201).json(databaseResult.data); }); + +/** + * @openapi + * /teamapplications/createFromAssistantApplication: + * post: + * tags: [teamapplications] + * summary: Make teamapplication from assistantapplication + * description: Make teamapplication from assistantapplication + * requestBody: + * required: true + * content: + * json: + * schema: + * $ref: "#/components/schemas/teamApplicationRequest" + * responses: + * 201: + * description: Successfull response + * content: + * application/json: + * schema: + * $ref: "#/components/schemas/teamApplication" + */ +teamApplicationRouter.post( + "/createFromAssistantApplication/", + async (req, res, next) => { + const teamApplicationBodyResult = teamInterestParser.safeParse(req.body); + + if (!teamApplicationBodyResult.success) { + const error = clientError( + 400, + "Invalid request format", + teamApplicationBodyResult.error, + ); + return next(error); + } + const databaseResult = await createTeamApplicationFromAssistantApplication( + teamApplicationBodyResult.data, + ); + if (!databaseResult.success) { + const error = clientError( + 400, + "Failed to execute the database command", + databaseResult.error, + ); + return next(error); + } + res.status(201).json(databaseResult.data); + }, +); From 574becb999ffe02ae2d4775926a438b2efc66729 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 17:35:11 +0200 Subject: [PATCH 3/9] feat: :sparkles: added composite key to schoolsemesterassistant table --- db/tables/school-semester-assistant.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/tables/school-semester-assistant.ts b/db/tables/school-semester-assistant.ts index 263c921..dbf52e4 100644 --- a/db/tables/school-semester-assistant.ts +++ b/db/tables/school-semester-assistant.ts @@ -1,5 +1,5 @@ import { relations } from "drizzle-orm"; -import { integer } from "drizzle-orm/pg-core"; +import { integer, primaryKey } from "drizzle-orm/pg-core"; import { mainSchema } from "./schema"; import { schoolsTable } from "./schools"; import { semestersTable } from "./semesters"; @@ -12,6 +12,11 @@ export const schoolSemesterAssistantsTable = mainSchema.table( semesterId: integer("semesterId").references(() => semestersTable.id).notNull(), assistantUserId: integer("userId").references(() => assistantUsersTable.id).notNull(), }, + (table) => ({ + pk: primaryKey({ + columns: [table.semesterId, table.assistantUserId], + }), + }), ); export const schoolSemesterAssistantsRelations = relations( From bd326ddab6c135e52f60f94bd514f311dd24eda9 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 17:38:47 +0200 Subject: [PATCH 4/9] style: :art: pnpm check --- db/tables/school-semester-assistant.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/db/tables/school-semester-assistant.ts b/db/tables/school-semester-assistant.ts index dbf52e4..f3892e0 100644 --- a/db/tables/school-semester-assistant.ts +++ b/db/tables/school-semester-assistant.ts @@ -9,8 +9,12 @@ export const schoolSemesterAssistantsTable = mainSchema.table( "schoolSemesterAssistant", { schoolId: integer("schoolId").references(() => schoolsTable.id), - semesterId: integer("semesterId").references(() => semestersTable.id).notNull(), - assistantUserId: integer("userId").references(() => assistantUsersTable.id).notNull(), + semesterId: integer("semesterId") + .references(() => semestersTable.id) + .notNull(), + assistantUserId: integer("userId") + .references(() => assistantUsersTable.id) + .notNull(), }, (table) => ({ pk: primaryKey({ From 76736574910295d8a2aa9b10d776149e51c19987 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 18:00:21 +0200 Subject: [PATCH 5/9] style: :art: renamed schoolsemesterassistant table to schoolassignment --- db/tables/{school-semester-assistant.ts => schoolAssignment.ts} | 0 db/tables/schools.ts | 2 +- db/tables/semesters.ts | 2 +- db/tables/users.ts | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename db/tables/{school-semester-assistant.ts => schoolAssignment.ts} (100%) diff --git a/db/tables/school-semester-assistant.ts b/db/tables/schoolAssignment.ts similarity index 100% rename from db/tables/school-semester-assistant.ts rename to db/tables/schoolAssignment.ts diff --git a/db/tables/schools.ts b/db/tables/schools.ts index 2084e28..327239b 100644 --- a/db/tables/schools.ts +++ b/db/tables/schools.ts @@ -2,7 +2,7 @@ import { relations } from "drizzle-orm"; import { boolean, integer, serial, text } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolSemesterAssistantsTable } from "./school-semester-assistant"; +import { schoolSemesterAssistantsTable } from "./schoolAssignment"; export const schoolsTable = mainSchema.table("schools", { id: serial("id").primaryKey(), diff --git a/db/tables/semesters.ts b/db/tables/semesters.ts index dc9e824..bb0899e 100644 --- a/db/tables/semesters.ts +++ b/db/tables/semesters.ts @@ -8,7 +8,7 @@ import { } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolSemesterAssistantsTable } from "./school-semester-assistant"; +import { schoolSemesterAssistantsTable } from "./schoolAssignment"; import { teamSemesterUsersTable } from "./team-semester-user"; export const semestersTable = mainSchema.table("semesters", { diff --git a/db/tables/users.ts b/db/tables/users.ts index b0ba0ab..a81cbcc 100644 --- a/db/tables/users.ts +++ b/db/tables/users.ts @@ -5,7 +5,7 @@ import { integer, serial, text } from "drizzle-orm/pg-core"; import { expensesTable } from "@/db/tables/expenses"; import { fieldsOfStudyTable } from "@/db/tables/fields-of-study"; import { teamsTable } from "@/db/tables/teams"; -import { schoolSemesterAssistantsTable } from "./school-semester-assistant"; +import { schoolSemesterAssistantsTable } from "./schoolAssignment"; import { teamSemesterUsersTable } from "./team-semester-user"; export const usersTable = mainSchema.table("users", { From 46d4f0e1f7638eac385717c0b39c007c4b2cb9d3 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 18:01:34 +0200 Subject: [PATCH 6/9] style: :art: changed file name to kebab-case --- db/tables/{schoolAssignment.ts => school-assignment.ts} | 0 db/tables/schools.ts | 2 +- db/tables/semesters.ts | 2 +- db/tables/users.ts | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename db/tables/{schoolAssignment.ts => school-assignment.ts} (100%) diff --git a/db/tables/schoolAssignment.ts b/db/tables/school-assignment.ts similarity index 100% rename from db/tables/schoolAssignment.ts rename to db/tables/school-assignment.ts diff --git a/db/tables/schools.ts b/db/tables/schools.ts index 327239b..9eb0657 100644 --- a/db/tables/schools.ts +++ b/db/tables/schools.ts @@ -2,7 +2,7 @@ import { relations } from "drizzle-orm"; import { boolean, integer, serial, text } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolSemesterAssistantsTable } from "./schoolAssignment"; +import { schoolSemesterAssistantsTable } from "./school-assignment"; export const schoolsTable = mainSchema.table("schools", { id: serial("id").primaryKey(), diff --git a/db/tables/semesters.ts b/db/tables/semesters.ts index bb0899e..aa804fc 100644 --- a/db/tables/semesters.ts +++ b/db/tables/semesters.ts @@ -8,7 +8,7 @@ import { } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolSemesterAssistantsTable } from "./schoolAssignment"; +import { schoolSemesterAssistantsTable } from "./school-assignment"; import { teamSemesterUsersTable } from "./team-semester-user"; export const semestersTable = mainSchema.table("semesters", { diff --git a/db/tables/users.ts b/db/tables/users.ts index a81cbcc..d2ce635 100644 --- a/db/tables/users.ts +++ b/db/tables/users.ts @@ -5,7 +5,7 @@ import { integer, serial, text } from "drizzle-orm/pg-core"; import { expensesTable } from "@/db/tables/expenses"; import { fieldsOfStudyTable } from "@/db/tables/fields-of-study"; import { teamsTable } from "@/db/tables/teams"; -import { schoolSemesterAssistantsTable } from "./schoolAssignment"; +import { schoolSemesterAssistantsTable } from "./school-assignment"; import { teamSemesterUsersTable } from "./team-semester-user"; export const usersTable = mainSchema.table("users", { From ff933e81733084981be40d9e7f5540766120ca48 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 18:17:15 +0200 Subject: [PATCH 7/9] style: :art: changed all instances of schoolsemesterassistant to schoolassignment --- database-diagram.md | 8 ++++---- db/tables/school-assignment.ts | 14 +++++++------- db/tables/schools.ts | 4 ++-- db/tables/semesters.ts | 4 ++-- db/tables/users.ts | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/database-diagram.md b/database-diagram.md index 86adad1..92a79c8 100644 --- a/database-diagram.md +++ b/database-diagram.md @@ -99,7 +99,7 @@ erDiagram string contactPersonEmail boolean isInternational } - SCHOOL_SEMESTER_ASSISTANT{ + SCHOOL_ASSIGNMENT{ int school FK int semester FK int user FK @@ -122,9 +122,9 @@ erDiagram SEMESTER }|--|| VEKTOR_DEPARTMENT : department SCHOOL }|--|| VEKTOR_DEPARTMENT : department SEMESTER }o--|| ASSISTENT_APPLICATION : admissionPeriod - SCHOOL_SEMESTER_ASSISTANT ||--o{ SCHOOL : schoolSemesterAssistant - SCHOOL_SEMESTER_ASSISTANT ||--o{ SEMESTER : schoolSemesterAssistant - SCHOOL_SEMESTER_ASSISTANT ||--o{ USER : shcoolSemesterAssistant + SCHOOL_ASSIGNMENT ||--o{ SCHOOL : schoolAssignment + SCHOOL_ASSIGNMENT ||--o{ SEMESTER : schoolAssignment + SCHOOL_ASSIGNMENT ||--o{ USER : schoolAssignment TEAM_SEMESTER_USER ||--o{ TEAM : teamSemesterUser TEAM_SEMESTER_USER ||--o{ SEMESTER : teamSemesterUser TEAM_SEMESTER_USER ||--o{ USER : teamSemesterUser diff --git a/db/tables/school-assignment.ts b/db/tables/school-assignment.ts index f3892e0..fd8fcec 100644 --- a/db/tables/school-assignment.ts +++ b/db/tables/school-assignment.ts @@ -5,8 +5,8 @@ import { schoolsTable } from "./schools"; import { semestersTable } from "./semesters"; import { assistantUsersTable } from "./users"; -export const schoolSemesterAssistantsTable = mainSchema.table( - "schoolSemesterAssistant", +export const schoolAssignmentTable = mainSchema.table( + "schoolAssignment", { schoolId: integer("schoolId").references(() => schoolsTable.id), semesterId: integer("semesterId") @@ -23,19 +23,19 @@ export const schoolSemesterAssistantsTable = mainSchema.table( }), ); -export const schoolSemesterAssistantsRelations = relations( - schoolSemesterAssistantsTable, +export const schoolAssignmentRelations = relations( + schoolAssignmentTable, ({ one }) => ({ school: one(schoolsTable, { - fields: [schoolSemesterAssistantsTable.schoolId], + fields: [schoolAssignmentTable.schoolId], references: [schoolsTable.id], }), semester: one(semestersTable, { - fields: [schoolSemesterAssistantsTable.semesterId], + fields: [schoolAssignmentTable.semesterId], references: [semestersTable.id], }), assistantUser: one(assistantUsersTable, { - fields: [schoolSemesterAssistantsTable.assistantUserId], + fields: [schoolAssignmentTable.assistantUserId], references: [assistantUsersTable.id], }), }), diff --git a/db/tables/schools.ts b/db/tables/schools.ts index 9eb0657..a2a8915 100644 --- a/db/tables/schools.ts +++ b/db/tables/schools.ts @@ -2,7 +2,7 @@ import { relations } from "drizzle-orm"; import { boolean, integer, serial, text } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolSemesterAssistantsTable } from "./school-assignment"; +import { schoolAssignmentTable } from "./school-assignment"; export const schoolsTable = mainSchema.table("schools", { id: serial("id").primaryKey(), @@ -19,5 +19,5 @@ export const schoolsRelations = relations(schoolsTable, ({ one, many }) => ({ fields: [schoolsTable.departmentId], references: [departmentsTable.id], }), - semesterAssistants: many(schoolSemesterAssistantsTable), + semesterAssistants: many(schoolAssignmentTable), })); diff --git a/db/tables/semesters.ts b/db/tables/semesters.ts index aa804fc..d3295ea 100644 --- a/db/tables/semesters.ts +++ b/db/tables/semesters.ts @@ -8,7 +8,7 @@ import { } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolSemesterAssistantsTable } from "./school-assignment"; +import { schoolAssignmentTable } from "./school-assignment"; import { teamSemesterUsersTable } from "./team-semester-user"; export const semestersTable = mainSchema.table("semesters", { @@ -41,7 +41,7 @@ export const semestersRelations = relations( fields: [semestersTable.id], references: [semestersTable.lastSemesterId], }), - schoolAssistants: many(schoolSemesterAssistantsTable), + schoolAssistants: many(schoolAssignmentTable), teamUsers: many(teamSemesterUsersTable), }), ); diff --git a/db/tables/users.ts b/db/tables/users.ts index d2ce635..7a92e27 100644 --- a/db/tables/users.ts +++ b/db/tables/users.ts @@ -5,8 +5,8 @@ import { integer, serial, text } from "drizzle-orm/pg-core"; import { expensesTable } from "@/db/tables/expenses"; import { fieldsOfStudyTable } from "@/db/tables/fields-of-study"; import { teamsTable } from "@/db/tables/teams"; -import { schoolSemesterAssistantsTable } from "./school-assignment"; import { teamSemesterUsersTable } from "./team-semester-user"; +import { schoolAssignmentTable } from "./school-assignment"; export const usersTable = mainSchema.table("users", { id: serial("id").primaryKey(), @@ -65,6 +65,6 @@ export const assistantUsersRelation = relations( fields: [assistantUsersTable.id], references: [usersTable.id], }), - schoolSemesters: many(schoolSemesterAssistantsTable), + schoolSemesters: many(schoolAssignmentTable), }), ); From 182ab11f242dd62a73249406f7fb4bc06096aef3 Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 18:17:56 +0200 Subject: [PATCH 8/9] style: :art: pnpm check --- db/tables/users.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/tables/users.ts b/db/tables/users.ts index 7a92e27..5c67203 100644 --- a/db/tables/users.ts +++ b/db/tables/users.ts @@ -5,8 +5,8 @@ import { integer, serial, text } from "drizzle-orm/pg-core"; import { expensesTable } from "@/db/tables/expenses"; import { fieldsOfStudyTable } from "@/db/tables/fields-of-study"; import { teamsTable } from "@/db/tables/teams"; -import { teamSemesterUsersTable } from "./team-semester-user"; import { schoolAssignmentTable } from "./school-assignment"; +import { teamSemesterUsersTable } from "./team-semester-user"; export const usersTable = mainSchema.table("users", { id: serial("id").primaryKey(), From 5f3c9bcac73b09f1671ae3b38f05660f88b58e1a Mon Sep 17 00:00:00 2001 From: TobiasH05 Date: Wed, 15 Oct 2025 18:31:03 +0200 Subject: [PATCH 9/9] style: :art: changed schoolAssignments to plural --- database-diagram.md | 8 ++++---- ...{school-assignment.ts => school-assignments.ts} | 14 +++++++------- db/tables/schools.ts | 4 ++-- db/tables/semesters.ts | 4 ++-- db/tables/users.ts | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) rename db/tables/{school-assignment.ts => school-assignments.ts} (74%) diff --git a/database-diagram.md b/database-diagram.md index 92a79c8..cd0f9a4 100644 --- a/database-diagram.md +++ b/database-diagram.md @@ -99,7 +99,7 @@ erDiagram string contactPersonEmail boolean isInternational } - SCHOOL_ASSIGNMENT{ + SCHOOL_ASSIGNMENTS{ int school FK int semester FK int user FK @@ -122,9 +122,9 @@ erDiagram SEMESTER }|--|| VEKTOR_DEPARTMENT : department SCHOOL }|--|| VEKTOR_DEPARTMENT : department SEMESTER }o--|| ASSISTENT_APPLICATION : admissionPeriod - SCHOOL_ASSIGNMENT ||--o{ SCHOOL : schoolAssignment - SCHOOL_ASSIGNMENT ||--o{ SEMESTER : schoolAssignment - SCHOOL_ASSIGNMENT ||--o{ USER : schoolAssignment + SCHOOL_ASSIGNMENTS ||--o{ SCHOOL : schoolAssignments + SCHOOL_ASSIGNMENTS ||--o{ SEMESTER : schoolAssignments + SCHOOL_ASSIGNMENTS ||--o{ USER : schoolAssignments TEAM_SEMESTER_USER ||--o{ TEAM : teamSemesterUser TEAM_SEMESTER_USER ||--o{ SEMESTER : teamSemesterUser TEAM_SEMESTER_USER ||--o{ USER : teamSemesterUser diff --git a/db/tables/school-assignment.ts b/db/tables/school-assignments.ts similarity index 74% rename from db/tables/school-assignment.ts rename to db/tables/school-assignments.ts index fd8fcec..5870648 100644 --- a/db/tables/school-assignment.ts +++ b/db/tables/school-assignments.ts @@ -5,8 +5,8 @@ import { schoolsTable } from "./schools"; import { semestersTable } from "./semesters"; import { assistantUsersTable } from "./users"; -export const schoolAssignmentTable = mainSchema.table( - "schoolAssignment", +export const schoolAssignmentsTable = mainSchema.table( + "schoolAssignments", { schoolId: integer("schoolId").references(() => schoolsTable.id), semesterId: integer("semesterId") @@ -23,19 +23,19 @@ export const schoolAssignmentTable = mainSchema.table( }), ); -export const schoolAssignmentRelations = relations( - schoolAssignmentTable, +export const schoolAssignmentsRelations = relations( + schoolAssignmentsTable, ({ one }) => ({ school: one(schoolsTable, { - fields: [schoolAssignmentTable.schoolId], + fields: [schoolAssignmentsTable.schoolId], references: [schoolsTable.id], }), semester: one(semestersTable, { - fields: [schoolAssignmentTable.semesterId], + fields: [schoolAssignmentsTable.semesterId], references: [semestersTable.id], }), assistantUser: one(assistantUsersTable, { - fields: [schoolAssignmentTable.assistantUserId], + fields: [schoolAssignmentsTable.assistantUserId], references: [assistantUsersTable.id], }), }), diff --git a/db/tables/schools.ts b/db/tables/schools.ts index a2a8915..71a2127 100644 --- a/db/tables/schools.ts +++ b/db/tables/schools.ts @@ -2,7 +2,7 @@ import { relations } from "drizzle-orm"; import { boolean, integer, serial, text } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolAssignmentTable } from "./school-assignment"; +import { schoolAssignmentsTable } from "./school-assignments"; export const schoolsTable = mainSchema.table("schools", { id: serial("id").primaryKey(), @@ -19,5 +19,5 @@ export const schoolsRelations = relations(schoolsTable, ({ one, many }) => ({ fields: [schoolsTable.departmentId], references: [departmentsTable.id], }), - semesterAssistants: many(schoolAssignmentTable), + semesterAssistants: many(schoolAssignmentsTable), })); diff --git a/db/tables/semesters.ts b/db/tables/semesters.ts index d3295ea..f287225 100644 --- a/db/tables/semesters.ts +++ b/db/tables/semesters.ts @@ -8,7 +8,7 @@ import { } from "drizzle-orm/pg-core"; import { departmentsTable } from "./departments"; import { mainSchema } from "./schema"; -import { schoolAssignmentTable } from "./school-assignment"; +import { schoolAssignmentsTable } from "./school-assignments"; import { teamSemesterUsersTable } from "./team-semester-user"; export const semestersTable = mainSchema.table("semesters", { @@ -41,7 +41,7 @@ export const semestersRelations = relations( fields: [semestersTable.id], references: [semestersTable.lastSemesterId], }), - schoolAssistants: many(schoolAssignmentTable), + schoolAssistants: many(schoolAssignmentsTable), teamUsers: many(teamSemesterUsersTable), }), ); diff --git a/db/tables/users.ts b/db/tables/users.ts index 5c67203..f3405c4 100644 --- a/db/tables/users.ts +++ b/db/tables/users.ts @@ -5,7 +5,7 @@ import { integer, serial, text } from "drizzle-orm/pg-core"; import { expensesTable } from "@/db/tables/expenses"; import { fieldsOfStudyTable } from "@/db/tables/fields-of-study"; import { teamsTable } from "@/db/tables/teams"; -import { schoolAssignmentTable } from "./school-assignment"; +import { schoolAssignmentsTable } from "./school-assignments"; import { teamSemesterUsersTable } from "./team-semester-user"; export const usersTable = mainSchema.table("users", { @@ -65,6 +65,6 @@ export const assistantUsersRelation = relations( fields: [assistantUsersTable.id], references: [usersTable.id], }), - schoolSemesters: many(schoolAssignmentTable), + schoolSemesters: many(schoolAssignmentsTable), }), );