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
57 changes: 57 additions & 0 deletions db/migrations/20250810024421_create_team_roster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Knex } from "knex";

export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable("team_roster", (table) => {
table.uuid("id").primary().notNullable(); // UUID

table
.string("hackathon_id")
.notNullable()
.references("id")
.inTable("hackathons")
.onDelete("CASCADE")
.onUpdate("CASCADE");

table.uuid("team_id").notNullable(); // UUID identifier for the team
table.string("team_name", 80).notNullable(); // Team name (duplicated across rows)

table
.string("user_id")
.notNullable()
.references("id")
.inTable("users")
.onDelete("CASCADE")
.onUpdate("CASCADE");

table.enu("role", ["lead", "member"]).notNullable();

table.bigInteger("joined_at").unsigned().notNullable();
table.bigInteger("updated_at").unsigned().notNullable();

// Constraints
table.unique(
["hackathon_id", "user_id"],
"team_roster_hackathon_user_unique",
); // One team per user per hackathon
table.unique(
["hackathon_id", "team_id", "user_id"],
"team_roster_hackathon_team_user_unique",
); // No duplicate row in same team

// Indexes
table.index(
["hackathon_id", "team_id"],
"team_roster_hackathon_team_index",
);
table.index(
["hackathon_id", "team_name"],
"team_roster_hackathon_name_index",
);
table.index(["user_id"], "team_roster_user_index");
table.index(["team_id"], "team_roster_team_index");
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists("team_roster");
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { FinanceModule } from "modules/finance/finance.module";
import { WalletModule } from "modules/wallet/wallet.module";
import { EmailModule } from "modules/email/email.module";
import { InventoryModule } from "modules/inventory/inventory.module";
import { TeamsModule } from "modules/teams/teams.module";

@Module({
imports: [
Expand Down Expand Up @@ -98,6 +99,7 @@ import { InventoryModule } from "modules/inventory/inventory.module";
WalletModule,
EmailModule,
InventoryModule,
TeamsModule,

// WebSocket
SocketModule,
Expand Down
89 changes: 89 additions & 0 deletions src/entities/team-roster.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { ApiProperty, PickType } from "@nestjs/swagger";
import { Column, ID, Table } from "common/objection";
import { Entity } from "entities/base.entity";
import { IsEnum, IsString, IsNumber } from "class-validator";
import { User } from "./user.entity";
import { Hackathon } from "./hackathon.entity";

export enum TeamRole {
LEAD = "lead",
MEMBER = "member",
}

@Table({
name: "team_roster",
relationMappings: {
user: {
relation: Entity.BelongsToOneRelation,
modelClass: User,
join: {
from: "team_roster.userId",
to: "users.id",
},
},
hackathon: {
relation: Entity.BelongsToOneRelation,
modelClass: Hackathon,
join: {
from: "team_roster.hackathonId",
to: "hackathons.id",
},
},
},
})
export class TeamRoster extends Entity {
@ApiProperty()
@IsString()
@ID({ type: "string" })
id: string;

@ApiProperty()
@IsString()
@Column({ type: "string" })
hackathonId: string;

@ApiProperty()
@IsString()
@Column({ type: "string" })
teamId: string;

@ApiProperty()
@IsString()
@Column({ type: "string" })
teamName: string;

@ApiProperty()
@IsString()
@Column({ type: "string" })
userId: string;

@ApiProperty({ enum: TeamRole })
@IsEnum(TeamRole)
@Column({ type: "string" })
role: TeamRole;

@ApiProperty()
@IsNumber()
@Column({ type: "integer" })
joinedAt: number;

@ApiProperty()
@IsNumber()
@Column({ type: "integer" })
updatedAt: number;

// Relations
user?: User;
hackathon?: Hackathon;
}

export class TeamRosterEntity extends PickType(TeamRoster, [
"id",
"hackathonId",
"teamId",
"teamName",
"userId",
"role",
"joinedAt",
"updatedAt",
] as const) {}
Loading