Merge pull request #60 from detleph/create-pull-request/patch

Reformat files using prettier
This commit is contained in:
Stephan
2022-05-30 21:59:20 +02:00
committed by GitHub
4 changed files with 84 additions and 67 deletions
+5 -2
View File
@@ -159,12 +159,15 @@ export const updateEvent = async (req: Request<{ pid: string }>, res: Response)
if (result.success === false) { if (result.success === false) {
return res.status(400).json( return res.status(400).json(
generateInvalidBodyError({ generateInvalidBodyError(
{
name: DataType.STRING, name: DataType.STRING,
date: DataType.DATETIME, date: DataType.DATETIME,
briefDescription: DataType.STRING, briefDescription: DataType.STRING,
["fullDescription?"]: DataType.STRING, ["fullDescription?"]: DataType.STRING,
}, result.error) },
result.error
)
); );
} }
+13 -7
View File
@@ -5,7 +5,14 @@ import { z } from "zod";
import prisma from "../lib/prisma"; import prisma from "../lib/prisma";
import { requireResponsibleForGroup } from "../Middleware/auth/auth"; import { requireResponsibleForGroup } from "../Middleware/auth/auth";
import NotFoundError from "../Middleware/error/NotFoundError"; import NotFoundError from "../Middleware/error/NotFoundError";
import { createInsufficientPermissionsError, DataType, generateError, generateInvalidBodyError, genericError, handleCreateByName } from "./common"; import {
createInsufficientPermissionsError,
DataType,
generateError,
generateInvalidBodyError,
genericError,
handleCreateByName,
} from "./common";
const updateGroupBody = z const updateGroupBody = z
.object({ .object({
@@ -131,7 +138,7 @@ export const createGroup = async (req: Request<{ organisationPid: string }, {},
export const updateGroup = async (req: Request<{ pid: string }>, res: Response) => { export const updateGroup = async (req: Request<{ pid: string }>, res: Response) => {
const result = updateGroupBody.safeParse(req.body); const result = updateGroupBody.safeParse(req.body);
if(result.success === false){ if (result.success === false) {
return res.status(400).json( return res.status(400).json(
generateInvalidBodyError( generateInvalidBodyError(
{ {
@@ -147,7 +154,7 @@ export const updateGroup = async (req: Request<{ pid: string }>, res: Response)
const body = result.data; const body = result.data;
const { pid } = req.params; const { pid } = req.params;
requireResponsibleForGroup(req.auth, pid) requireResponsibleForGroup(req.auth, pid);
try { try {
const group = await prisma.group.update({ const group = await prisma.group.update({
@@ -164,15 +171,14 @@ export const updateGroup = async (req: Request<{ pid: string }>, res: Response)
type: "success", type: "success",
payload: { group }, payload: { group },
}); });
} catch (e) { } catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError("group", pid) throw new NotFoundError("group", pid);
} }
throw e; throw e;
} }
} };
interface DeleteGroupQueryParams { interface DeleteGroupQueryParams {
pid: string; pid: string;
@@ -191,7 +197,7 @@ export const deleteGroup = async (req: Request<DeleteGroupQueryParams>, res: Res
return res.status(204).end(); return res.status(204).end();
} catch (e) { } catch (e) {
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError("group", pid) throw new NotFoundError("group", pid);
} }
throw e; throw e;
+18 -13
View File
@@ -102,7 +102,7 @@ export const updateRoleScore = async (req: Request<{ pid: string }, {}, { score:
const { score } = req.body; const { score } = req.body;
if(typeof score !== "string"){ if (typeof score !== "string") {
res.status(400).json(generateInvalidBodyError({ score: DataType.STRING })); res.status(400).json(generateInvalidBodyError({ score: DataType.STRING }));
} }
@@ -115,20 +115,26 @@ export const updateRoleScore = async (req: Request<{ pid: string }, {}, { score:
select: { select: {
pid: true, pid: true,
score: true, score: true,
schema: { select: { schema: {
select: {
pid: true, pid: true,
name: true, name: true,
} }, },
participant: { select: { },
participant: {
select: {
pid: true, pid: true,
firstName: true, firstName: true,
lastName: true, lastName: true,
} }, },
team: { select: { },
team: {
select: {
pid: true, pid: true,
name: true, name: true,
}} },
} },
},
}); });
res.status(200).json({ res.status(200).json({
@@ -137,18 +143,17 @@ export const updateRoleScore = async (req: Request<{ pid: string }, {}, { score:
role, role,
}, },
}); });
} catch (e) { } catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError("role", pid) throw new NotFoundError("role", pid);
} }
throw e; throw e;
} }
} };
export async function deleteRolesFromTeam(teamPid: string){ export async function deleteRolesFromTeam(teamPid: string) {
await prisma.role.deleteMany({ await prisma.role.deleteMany({
where: { team: { pid: teamPid, } } where: { team: { pid: teamPid } },
}); });
} }
+8 -5
View File
@@ -145,14 +145,17 @@ export const updateRoleSchema = async (req: Request<{ pid: string }>, res: Respo
if (result.success === false) { if (result.success === false) {
return res.status(400).json( return res.status(400).json(
generateInvalidBodyError({ generateInvalidBodyError(
{
name: DataType.STRING, name: DataType.STRING,
schema: DataType.RESULT_SCHEMA, schema: DataType.RESULT_SCHEMA,
}, result.error) },
result.error
)
); );
} }
const {name, schema} = result.data; const { name, schema } = result.data;
const validatedSchema = parseSchema(schema); const validatedSchema = parseSchema(schema);
@@ -172,7 +175,7 @@ export const updateRoleSchema = async (req: Request<{ pid: string }>, res: Respo
}); });
} catch (e) { } catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
throw new NotFoundError("roleSchema", pid) throw new NotFoundError("roleSchema", pid);
} }
throw e; throw e;
@@ -197,7 +200,7 @@ export const deleteRoleSchema = async (req: Request<{ pid: string }>, res: Respo
throw e; throw e;
} }
} };
interface visualParams { interface visualParams {
schemaPid: string; schemaPid: string;