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

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable("projects", (table) => {
table
.uuid("team_id")
.nullable()
.references("id")
.inTable("teams")
.onDelete("SET NULL")
.onUpdate("CASCADE");
table.string("devpost_link").nullable();
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable("projects", (table) => {
table.dropColumn("team_id");
table.dropColumn("devpost_link");
});
}
24 changes: 23 additions & 1 deletion src/entities/project.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, PickType } from "@nestjs/swagger";
import { IsOptional, IsString } from "class-validator";
import { IsOptional, IsString, IsUrl } from "class-validator";
import { Column, ID, Table } from "common/objection";
import { Entity } from "entities/base.entity";

Expand All @@ -14,6 +14,14 @@ import { Entity } from "entities/base.entity";
to: "scores.projectId",
},
},
team: {
relation: Entity.BelongsToOneRelation,
modelClass: "team.entity.js",
join: {
from: "projects.teamId",
to: "teams.id",
},
},
},
modifiers: {
projectsByHackathon: async (qb, id) =>
Expand Down Expand Up @@ -42,11 +50,25 @@ export class Project extends Entity {
@IsString()
@Column({ type: "string", required: false })
categories: string;

@ApiProperty({ required: false, description: "Team associated with this project" })
@IsOptional()
@IsString()
@Column({ type: "string", required: false })
teamId?: string;

@ApiProperty({ required: false, description: "Devpost submission link" })
@IsOptional()
@IsUrl({}, { message: "Must be a valid URL" })
@Column({ type: "string", required: false })
devpostLink?: string;
}

export class ProjectEntity extends PickType(Project, [
"id",
"name",
"hackathonId",
"categories",
"teamId",
"devpostLink",
] as const) {}
3 changes: 2 additions & 1 deletion src/modules/judging/judging.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { JudgingController } from "modules/judging/judging.controller";
import { JudgingService } from "modules/judging/judging.service";
import { Organizer } from "entities/organizer.entity";
import { Hackathon } from "entities/hackathon.entity";
import { Team } from "entities/team.entity";

@Module({
imports: [ObjectionModule.forFeature([Organizer, Project, Score, Hackathon])],
imports: [ObjectionModule.forFeature([Organizer, Project, Score, Hackathon, Team])],
controllers: [JudgingController, ProjectController, ScoreController],
providers: [JudgingService],
})
Expand Down
59 changes: 57 additions & 2 deletions src/modules/judging/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Get,
HttpCode,
HttpStatus,
NotFoundException,
Param,
ParseIntPipe,
Patch,
Expand All @@ -18,6 +19,7 @@ import {
} from "@nestjs/common";
import { InjectRepository, Repository } from "common/objection";
import { Project, ProjectEntity } from "entities/project.entity";
import { Team } from "entities/team.entity";
import { ApiTags, OmitType, PartialType } from "@nestjs/swagger";
import { Role, Roles } from "common/gcp";
import { ApiDoc } from "common/docs";
Expand All @@ -39,6 +41,8 @@ export class ProjectController {
private readonly projectRepo: Repository<Project>,
@InjectRepository(Hackathon)
private readonly hackathonRepo: Repository<Hackathon>,
@InjectRepository(Team)
private readonly teamRepo: Repository<Team>,
) {}

@Get("/")
Expand All @@ -54,7 +58,7 @@ export class ProjectController {
}

@Post("/")
@Roles(Role.TEAM)
@Roles(Role.NONE)
@ApiDoc({
summary: "Create a Project",
request: {
Expand All @@ -76,6 +80,19 @@ export class ProjectController {
)
data: ProjectCreateEntity,
) {
// Validate teamId if provided
if (data.teamId) {
const team = await this.teamRepo.findOne(data.teamId).exec();
if (!team) {
throw new BadRequestException(`Team with ID ${data.teamId} not found`);
}

// Check if team is active
if (!team.isActive) {
throw new BadRequestException("Cannot assign project to inactive team");
}
}

return this.projectRepo.createOne(data).byHackathon();
}

Expand All @@ -98,8 +115,33 @@ export class ProjectController {
return this.projectRepo.findOne(id).exec();
}

@Get("team/:teamId")
@Roles(Role.NONE)
@ApiDoc({
summary: "Get Projects by Team ID",
params: [
{
name: "teamId",
description: "ID must be set to a team's ID",
},
],
response: {
ok: { type: [ProjectEntity] },
},
auth: Role.NONE,
})
async getProjectsByTeam(@Param("teamId") teamId: string) {
// Validate team exists
const team = await this.teamRepo.findOne(teamId).exec();
if (!team) {
throw new NotFoundException(`Team with ID ${teamId} not found`);
}

return this.projectRepo.findAll().byHackathon().where("teamId", teamId);
}

@Patch(":id")
@Roles(Role.TEAM)
@Roles(Role.NONE)
@ApiDoc({
summary: "Patch a Project",
params: [
Expand Down Expand Up @@ -128,6 +170,19 @@ export class ProjectController {
)
data: ProjectPatchEntity,
) {
// Validate teamId if provided
if (data.teamId) {
const team = await this.teamRepo.findOne(data.teamId).exec();
if (!team) {
throw new BadRequestException(`Team with ID ${data.teamId} not found`);
}

// Check if team is active
if (!team.isActive) {
throw new BadRequestException("Cannot assign project to inactive team");
}
}

return this.projectRepo.patchOne(id, data).exec();
}

Expand Down