-
Notifications
You must be signed in to change notification settings - Fork 0
make assistant application and team application work #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
solvhold
merged 19 commits into
main
from
vf-247-make-assistant-application-and-team-application-work
Apr 7, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0936320
feat: :art: structure the application tables to be a superclass with …
e23b10c
style: change filename
3481610
fix: fix wrong name
72de241
feat: :sparkles: update db access request for new table structure
3c87006
Merge branch 'main' into vf-247-make-assistant-application-and-team-a…
961bb59
fix: fix imports
fa90301
fix: update import
65a9134
fix: fix wrong names and imports
4ad0039
feat: update import, update insert db access
89eea8f
feat: update request handling to fit new table structure for applicat…
d4f212e
fix: update variable name
98e117e
feat: fix router error
e634165
fix: run pnpm check
d54cd72
fix: remove old file
3884dee
Merge branch 'main' into vf-247-make-assistant-application-and-team-a…
solvhold d7a4454
fix: merge fix
7ae24a9
fix: fix seeding
2aee151
feat: replace .transaction().then() with newDatabaseTransaction
a8f471d
fix: pnpm check
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { mainSchema } from "@/db/tables/schema"; | ||
| import { relations } from "drizzle-orm"; | ||
| import { date, integer, serial, text } from "drizzle-orm/pg-core"; | ||
|
|
||
| import { teamsTable } from "@/db/tables/teams"; | ||
| import { fieldsOfStudyTable } from "./fields-of-study"; | ||
|
|
||
| export const gendersEnum = mainSchema.enum("gender", [ | ||
| "female", | ||
| "male", | ||
| "other", | ||
| ]); | ||
|
|
||
| export const applicationsTable = mainSchema.table("applications", { | ||
| id: serial("id").primaryKey(), | ||
| firstName: text("firstname").notNull(), | ||
| lastName: text("lastname").notNull(), | ||
| gender: gendersEnum("gender").notNull(), | ||
| email: text("email").notNull(), | ||
| fieldOfStudyId: integer("fieldOfStudyId") | ||
| .notNull() | ||
| .references(() => fieldsOfStudyTable.id), | ||
| yearOfStudy: integer("yearOfStudy").notNull(), | ||
| phonenumber: text("phonenumber").notNull(), | ||
| submitDate: date("submitDate", { mode: "date" }).defaultNow().notNull(), | ||
| }); | ||
|
|
||
| export const applicationsRelations = relations( | ||
| applicationsTable, | ||
| ({ one, many }) => ({ | ||
| fieldOfStudy: one(fieldsOfStudyTable, { | ||
| fields: [applicationsTable.fieldOfStudyId], | ||
| references: [fieldsOfStudyTable.id], | ||
| }), | ||
| assistantApplication: one(assistantApplicationsTable, { | ||
| fields: [applicationsTable.id], | ||
| references: [assistantApplicationsTable.id], | ||
| }), | ||
| teamApplication: many(teamApplicationsTable), | ||
| }), | ||
| ); | ||
|
|
||
| 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 teamApplicationsRelations = relations( | ||
| teamApplicationsTable, | ||
| ({ one }) => ({ | ||
| superApplication: one(applicationsTable, { | ||
| fields: [teamApplicationsTable.id], | ||
| references: [applicationsTable.id], | ||
| }), | ||
| team: one(teamsTable, { | ||
| fields: [teamApplicationsTable.teamId], | ||
| references: [teamsTable.id], | ||
| }), | ||
| }), | ||
| ); | ||
|
|
||
| export const assistantApplicationsTable = mainSchema.table( | ||
| "assistantApplications", | ||
| { | ||
| id: integer("id") | ||
| .primaryKey() | ||
| .references(() => applicationsTable.id), | ||
| }, | ||
| ); | ||
|
|
||
| export const assistantApplicationsRelations = relations( | ||
| assistantApplicationsTable, | ||
| ({ one }) => ({ | ||
| superApplication: one(applicationsTable, { | ||
| fields: [assistantApplicationsTable.id], | ||
| references: [applicationsTable.id], | ||
| }), | ||
| }), | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { database } from "@/db/setup/query-postgres"; | ||
| import { | ||
| applicationsTable, | ||
| teamApplicationsTable, | ||
| } from "@/db/tables/applications"; | ||
| import type { OrmResult } from "@/src/error/orm-error"; | ||
| import type { | ||
| NewApplication, | ||
| NewTeamApplication, | ||
| } from "@/src/request-handling/applications"; | ||
| import type { QueryParameters } from "@/src/request-handling/common"; | ||
| import type { | ||
| ApplicationKey, | ||
| TeamApplication, | ||
| TeamKey, | ||
| } from "@/src/response-handling/applications"; | ||
| import { eq, inArray } from "drizzle-orm"; | ||
| import { newDatabaseTransaction } from "./common"; | ||
|
|
||
| export const selectTeamApplications = async ( | ||
kyrkjedelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| parameters: QueryParameters, | ||
| ): Promise<OrmResult<TeamApplication[]>> => { | ||
| return await newDatabaseTransaction(database, async (tx) => { | ||
| const teamApplications = await tx | ||
| .select({ | ||
| id: applicationsTable.id, | ||
| teamId: teamApplicationsTable.teamId, | ||
| firstName: applicationsTable.firstName, | ||
| lastName: applicationsTable.lastName, | ||
| gender: applicationsTable.gender, | ||
| email: applicationsTable.email, | ||
| fieldOfStudyId: applicationsTable.fieldOfStudyId, | ||
| yearOfStudy: applicationsTable.yearOfStudy, | ||
| phonenumber: applicationsTable.phonenumber, | ||
| motivationText: teamApplicationsTable.motivationText, | ||
| biography: teamApplicationsTable.biography, | ||
| submitDate: applicationsTable.submitDate, | ||
| }) | ||
| .from(teamApplicationsTable) | ||
| .innerJoin( | ||
| applicationsTable, | ||
| eq(teamApplicationsTable.id, applicationsTable.id), | ||
| ) | ||
| .limit(parameters.limit) | ||
| .offset(parameters.offset); | ||
|
|
||
| return teamApplications; | ||
| }); | ||
| }; | ||
|
|
||
| export const selectTeamApplicationsByTeamId = async ( | ||
kyrkjedelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| teamId: TeamKey[], | ||
| parameters: QueryParameters, | ||
| ): Promise<OrmResult<TeamApplication[]>> => { | ||
| return await newDatabaseTransaction(database, async (tx) => { | ||
| const selectResult = await tx | ||
| .select({ | ||
| id: applicationsTable.id, | ||
| teamId: teamApplicationsTable.teamId, | ||
| firstName: applicationsTable.firstName, | ||
| lastName: applicationsTable.lastName, | ||
| gender: applicationsTable.gender, | ||
| email: applicationsTable.email, | ||
| fieldOfStudyId: applicationsTable.fieldOfStudyId, | ||
| yearOfStudy: applicationsTable.yearOfStudy, | ||
| phonenumber: applicationsTable.phonenumber, | ||
| motivationText: teamApplicationsTable.motivationText, | ||
| biography: teamApplicationsTable.biography, | ||
| submitDate: applicationsTable.submitDate, | ||
| }) | ||
| .from(teamApplicationsTable) | ||
| .where(inArray(teamApplicationsTable.id, teamId)) | ||
| .innerJoin( | ||
| applicationsTable, | ||
| eq(teamApplicationsTable.id, applicationsTable.id), | ||
| ) | ||
| .limit(parameters.limit) | ||
| .offset(parameters.offset); | ||
|
|
||
| return selectResult; | ||
| }); | ||
| }; | ||
|
|
||
| export const selectTeamApplicationsById = async ( | ||
| applicationIds: ApplicationKey[], | ||
kyrkjedelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ): Promise<OrmResult<TeamApplication[]>> => { | ||
| return await newDatabaseTransaction(database, async (tx) => { | ||
| const selectResult = await tx | ||
| .select({ | ||
| id: applicationsTable.id, | ||
| teamId: teamApplicationsTable.teamId, | ||
| firstName: applicationsTable.firstName, | ||
| lastName: applicationsTable.lastName, | ||
| gender: applicationsTable.gender, | ||
| email: applicationsTable.email, | ||
| fieldOfStudyId: applicationsTable.fieldOfStudyId, | ||
| yearOfStudy: applicationsTable.yearOfStudy, | ||
| phonenumber: applicationsTable.phonenumber, | ||
| motivationText: teamApplicationsTable.motivationText, | ||
| biography: teamApplicationsTable.biography, | ||
| submitDate: applicationsTable.submitDate, | ||
| }) | ||
| .from(teamApplicationsTable) | ||
| .where(inArray(teamApplicationsTable.id, applicationIds)) | ||
| .innerJoin( | ||
| applicationsTable, | ||
| eq(teamApplicationsTable.id, applicationsTable.id), | ||
| ); | ||
|
|
||
| return selectResult; | ||
| }); | ||
| }; | ||
|
|
||
| export async function insertTeamApplication( | ||
| teamApplication: NewTeamApplication & NewApplication, | ||
kyrkjedelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ): Promise<OrmResult<TeamApplication>> { | ||
| return await newDatabaseTransaction(database, async (tx) => { | ||
| const newApplication = await tx | ||
| .insert(applicationsTable) | ||
| .values({ | ||
| firstName: teamApplication.firstName, | ||
| lastName: teamApplication.lastName, | ||
| gender: teamApplication.gender, | ||
| email: teamApplication.email, | ||
| fieldOfStudyId: teamApplication.fieldOfStudyId, | ||
| yearOfStudy: teamApplication.yearOfStudy, | ||
| phonenumber: teamApplication.phonenumber, | ||
| }) | ||
| .returning(); | ||
| const newApplicationId = newApplication[0].id; | ||
|
|
||
| const newTeamApplicationResult = await tx | ||
| .insert(teamApplicationsTable) | ||
| .values({ | ||
| id: newApplicationId, | ||
| teamId: teamApplication.teamId, | ||
| motivationText: teamApplication.motivationText, | ||
| biography: teamApplication.biography, | ||
| }) | ||
| .returning(); | ||
|
|
||
| return { | ||
| ...newApplication[0], | ||
| ...newTeamApplicationResult[0], | ||
| }; | ||
| }); | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.