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
+9 -6
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, {
date: DataType.DATETIME, name: DataType.STRING,
briefDescription: DataType.STRING, date: DataType.DATETIME,
["fullDescription?"]: DataType.STRING, briefDescription: DataType.STRING,
}, result.error) ["fullDescription?"]: DataType.STRING,
},
result.error
)
); );
} }
+41 -35
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,48 +138,47 @@ 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(
{ {
name: DataType.STRING, name: DataType.STRING,
user_limit: DataType.NUMBER, user_limit: DataType.NUMBER,
level: DataType.NUMBER, level: DataType.NUMBER,
}, },
result.error result.error
) )
); );
} }
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({
where: { pid }, where: { pid },
data: { data: {
name: body.name, name: body.name,
user_limit: body.user_limit, user_limit: body.user_limit,
level: body.level, level: body.level,
}, },
select: basicGroup, select: basicGroup,
}); });
res.status(200).json({ res.status(200).json({
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;
+24 -19
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,40 +115,45 @@ 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: { },
pid: true, participant: {
firstName: true, select: {
lastName: true, pid: true,
} }, firstName: true,
team: { select: { lastName: true,
pid: true, },
name: true, },
}} team: {
} select: {
pid: true,
name: true,
},
},
},
}); });
res.status(200).json({ res.status(200).json({
type: "success", type: "success",
payload: { payload: {
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 } },
}); });
} }
+10 -7
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, {
schema: DataType.RESULT_SCHEMA, name: DataType.STRING,
}, result.error) schema: DataType.RESULT_SCHEMA,
},
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;