mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +02:00
Add routes for organisations
+ FIX: Change eventId type
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
@@ -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}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user