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
2 changes: 2 additions & 0 deletions openapi/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { teamApplicationSelectSchema } from "@/src/response-handling/application
import { expensesSelectSchema } from "@/src/response-handling/expenses";
import { sponsorsSelectSchema } from "@/src/response-handling/sponsors";

import { teamsRequestParser } from "@/src/request-handling/teams";
import {
assistantUserSelectSchema,
teamUserSelectSchema,
Expand Down Expand Up @@ -84,6 +85,7 @@ const openapiDocument = createDocument({
datePeriod: datePeriodParser,
teamApplication: teamApplicationSelectSchema,
teamApplicationRequest: teamApplicationParser,
teams: teamsRequestParser,
},
parameters: {
id: serialIdParser.openapi({ param: { in: "path", name: "id" } }),
Expand Down
14 changes: 14 additions & 0 deletions src/db-access/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ export const selectActiveTeams = async (
return teams;
});
};
export const selectInActiveTeams = async (
parameters: QueryParameters,
): Promise<OrmResult<Team[]>> => {
return await newDatabaseTransaction(database, async (tx) => {
const teams = await tx
.select()
.from(teamsTable)
.where(eq(teamsTable.active, false))
.limit(parameters.limit)
.offset(parameters.offset);

return teams;
});
};
31 changes: 31 additions & 0 deletions src/request-handling/teams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expensesTable } from "@/db/tables/expenses";
import { timeStringParser } from "@/lib/time-parsers";
import { serialIdParser } from "@/src/request-handling/common";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";

export const teamsRequestParser = z
Comment thread
solvhold marked this conversation as resolved.
.object({
departmentId: serialIdParser.describe("Id of corresponding department"),
name: z.string().min(1).describe("Name of team"),
email: z.string().email().describe("Email of team"),
description: z.string().min(1).describe("Description of team"),
shortDescription: z.string().min(1).describe("Short description of team"),
acceptApplication: z
Comment thread
solvhold marked this conversation as resolved.
.boolean()
.describe("Whether the team is accepting applications or not"),
active: z.boolean().describe("Whether the team is active or not"),
deadline: timeStringParser.describe("Deadline for applying to the team"),
})
.strict();

export const teamsRequestToInsertParser = teamsRequestParser
.extend({
name: teamsRequestParser.shape.name.trim(),
email: teamsRequestParser.shape.email.trim().toLowerCase(),
description: teamsRequestParser.shape.description.trim(),
shortDescription: teamsRequestParser.shape.shortDescription.trim(),
})
.pipe(createInsertSchema(expensesTable).strict().readonly());

export type NewTeam = z.infer<typeof teamsRequestToInsertParser>;
42 changes: 41 additions & 1 deletion src/routers/teams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { selectActiveTeams, selectTeamsById } from "@/src/db-access/teams";
import {
selectActiveTeams,
selectInActiveTeams,
selectTeamsById,
} from "@/src/db-access/teams";
import { clientError } from "@/src/error/http-errors";
import {
listQueryParser,
Expand Down Expand Up @@ -48,6 +52,42 @@ teamsRouter.get("/active", async (req, res, next) => {
}
res.json(results.data);
});

/**
* @openapi
* /teams/inactive/:
* get:
* tags: [teams]
* summary: Get all inactive teams
* description: Return all inactive teams
* parameters:
* - $ref: "#/components/parameters/offset"
* - $ref: "#/components/parameters/limit"
* responses:
* 200:
* description: Successfull response
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/teams"
*/
teamsRouter.get("/inactive", async (req, res, next) => {
const queryParametersResult = toListQueryParser.safeParse(req.query);
if (!queryParametersResult.success) {
return next(
clientError(400, "Invalid request format", queryParametersResult.error),
);
}

const results = await selectInActiveTeams(queryParametersResult.data);
if (!results.success) {
return next(
clientError(400, "Invalid request format", queryParametersResult.error),
);
}
res.json(results.data);
});

/**
* @openapi
* /teams/{teamId}/:
Expand Down
Loading