mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
Extract common function to handle selecting organisations
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user