Add routes for organisations

+ FIX: Change eventId type
This commit is contained in:
Stephan
2022-04-26 16:04:26 +02:00
parent 08e18db3c3
commit 831017e7c2
3 changed files with 40 additions and 4 deletions
+14 -4
View File
@@ -3,9 +3,9 @@ import { Request, Response } from "express";
import prisma from "../lib/prisma";
import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common";
export const _getAllOrganisations = async (res: Response, eventId: number | undefined = undefined) => {
export const _getAllOrganisations = async (res: Response, eventId: string | undefined = undefined) => {
const organisations = await prisma.organisation.findMany({
where: { eventId },
where: { event: { pid: eventId } },
select: { pid: true, name: true, event: { select: { pid: true, name: true } } },
});
@@ -22,9 +22,19 @@ interface GetAllOrganisationsSearchParams {
}
export const getAllOrganisations = async (req: Request<{}, {}, {}, GetAllOrganisationsSearchParams>, res: Response) => {
const eventId = parseInt(req.query.eventId || "");
// TODO: Maybe rename to eventPid
return _getAllOrganisations(res, req.query.eventId);
};
return _getAllOrganisations(res, isNaN(eventId) ? undefined : eventId);
interface GetAllOrganisationsWithParamQueryParams {
eventPid: string;
}
export const getAllOrganisationsWithParam = async (
req: Request<GetAllOrganisationsWithParamQueryParams>,
res: Response
) => {
return _getAllOrganisations(res, req.params.eventPid);
};
interface GetOrganisationQueryParams {
+23
View File
@@ -0,0 +1,23 @@
import express from "express";
import eventRouter from "./event.routes";
import {
createOrganisation,
getAllOrganisations,
getAllOrganisationsWithParam,
getOrganisation,
} from "../Controllers/organisation.controller";
import { requireAuthentication } from "../Middleware/auth/auth";
const router = express.Router();
router.get("/", getAllOrganisations);
router.get("/:pid", getOrganisation);
eventRouter.get("/:eventPid/organisations", getAllOrganisationsWithParam);
eventRouter.post<"/:eventPid/organisations", { eventPid: string }>(
"/:eventPid/organisations",
requireAuthentication,
createOrganisation
);
export default router;
+3
View File
@@ -4,6 +4,7 @@ import eventRouter from "./Routes/event.routes";
import adminAuthRouter from "./Routes/admin_auth.routes";
import argon2 from "argon2";
import adminRouter from "./Routes/admin.routes";
import organisationRouter from "./Routes/organisation.routes";
require("dotenv").config(); // Load dotenv config
@@ -46,6 +47,8 @@ async function main() {
app.use("/api/admins", adminRouter);
app.use("/api/organisations", organisationRouter);
app.listen(process.env.PORT, () => {
console.log(`Listening on Port: ${process.env.PORT}`);
});