Extract common function to handle selecting organisations

This commit is contained in:
Stephan
2022-04-26 16:04:26 +02:00
parent ab62e39d8e
commit 08e18db3c3
+13 -2
View File
@@ -3,12 +3,13 @@ import { Request, Response } from "express";
import prisma from "../lib/prisma";
import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common";
export const getAllOrganisations = async (req: Request, res: Response) => {
export const _getAllOrganisations = async (res: Response, eventId: number | undefined = undefined) => {
const organisations = await prisma.organisation.findMany({
where: { eventId },
select: { pid: true, name: true, event: { select: { pid: true, name: true } } },
});
res.status(200).json({
return res.status(200).json({
type: "success",
payload: {
organisations,
@@ -16,6 +17,16 @@ export const getAllOrganisations = async (req: Request, res: Response) => {
});
};
interface GetAllOrganisationsSearchParams {
eventId?: string;
}
export const getAllOrganisations = async (req: Request<{}, {}, {}, GetAllOrganisationsSearchParams>, res: Response) => {
const eventId = parseInt(req.query.eventId || "");
return _getAllOrganisations(res, isNaN(eventId) ? undefined : eventId);
};
interface GetOrganisationQueryParams {
pid: string;
}