Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions db/seeding/seeding-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import { teamsTable } from "@/db/tables/teams";
import { usersTable } from "@/db/tables/users";

export const seedingTables = {
departmentsTable,
fieldsOfStudyTable,
teamsTable,
usersTable,
// meetings,
//departmentsTable,
//fieldsOfStudyTable,
//teamsTable,
//usersTable,
//teamUsersTable, these two tables dont work currently
//assistantUsersTable,
//teamApplicationsTable,
expensesTable,
applicationsTable,
//expensesTable,
//applicationsTable,
// meetingsTable,
// schoolsTable
};
9 changes: 8 additions & 1 deletion db/tables/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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",
Expand All @@ -30,6 +31,9 @@ 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(),
});

Expand All @@ -40,12 +44,15 @@ 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],
}),
teamApplication: many(teamApplicationsTable),
interview: many(interviewsTable),
}),
);

Expand Down
2 changes: 2 additions & 0 deletions db/tables/semesters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
serial,
text,
} from "drizzle-orm/pg-core";
import { applicationsTable } from "./applications";
import { departmentsTable } from "./departments";
import { meetingsTable } from "./meetings";
import { mainSchema } from "./schema";
Expand Down Expand Up @@ -44,6 +45,7 @@ export const semestersRelations = relations(
}),
schoolAssistants: many(schoolAssignmentsTable),
teamUsers: many(teamSemesterUsersTable),
applications: many(applicationsTable),
meetings: many(meetingsTable),
}),
);
4 changes: 4 additions & 0 deletions src/db-access/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const selectTeamApplications = async (
motivationText: teamApplicationsTable.motivationText,
biography: teamApplicationsTable.biography,
teamInterest: teamApplicationsTable.teamInterest,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dette objektet ligner veldig på det under. Kan du dra det ut og resirkulere kode?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will make another issue for this

semester: applicationsTable.semester,
submitDate: applicationsTable.submitDate,
})
.from(teamApplicationsTable)
Expand Down Expand Up @@ -71,6 +72,7 @@ export const selectTeamApplicationsByTeamId = async (
motivationText: teamApplicationsTable.motivationText,
biography: teamApplicationsTable.biography,
teamInterest: teamApplicationsTable.teamInterest,
semester: applicationsTable.semester,
submitDate: applicationsTable.submitDate,
})
.from(teamApplicationsTable)
Expand Down Expand Up @@ -106,6 +108,7 @@ export const selectTeamApplicationsById = async (
motivationText: teamApplicationsTable.motivationText,
biography: teamApplicationsTable.biography,
teamInterest: teamApplicationsTable.teamInterest,
semester: applicationsTable.semester,
submitDate: applicationsTable.submitDate,
})
.from(teamApplicationsTable)
Expand Down Expand Up @@ -138,6 +141,7 @@ export async function insertTeamApplication(
fieldOfStudyId: teamApplication.fieldOfStudyId,
yearOfStudy: teamApplication.yearOfStudy,
phonenumber: teamApplication.phonenumber,
semester: teamApplication.semester,
})
.returning();
const newApplicationId = newApplication[0].id;
Expand Down
1 change: 1 addition & 0 deletions src/request-handling/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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();

Expand Down