mirror of
https://github.com/detleph/server.git
synced 2026-09-06 23:44:26 +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 prisma from "../lib/prisma";
|
||||||
import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common";
|
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({
|
const organisations = await prisma.organisation.findMany({
|
||||||
|
where: { eventId },
|
||||||
select: { pid: true, name: true, event: { select: { pid: true, name: true } } },
|
select: { pid: true, name: true, event: { select: { pid: true, name: true } } },
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({
|
return res.status(200).json({
|
||||||
type: "success",
|
type: "success",
|
||||||
payload: {
|
payload: {
|
||||||
organisations,
|
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 {
|
interface GetOrganisationQueryParams {
|
||||||
pid: string;
|
pid: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user