From 5efb3597fd3861bc6c01efb1e90b656042197e5d Mon Sep 17 00:00:00 2001 From: stephan418 Date: Mon, 30 May 2022 19:59:00 +0000 Subject: [PATCH] [create-pull-request] push formatted files --- src/Controllers/event.controller.ts | 15 +++-- src/Controllers/group.controllers.ts | 76 ++++++++++++----------- src/Controllers/role.controller.ts | 43 +++++++------ src/Controllers/role_schema.controller.ts | 17 ++--- 4 files changed, 84 insertions(+), 67 deletions(-) diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index e996351..03d0426 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -159,12 +159,15 @@ export const updateEvent = async (req: Request<{ pid: string }>, res: Response) if (result.success === false) { return res.status(400).json( - generateInvalidBodyError({ - name: DataType.STRING, - date: DataType.DATETIME, - briefDescription: DataType.STRING, - ["fullDescription?"]: DataType.STRING, - }, result.error) + generateInvalidBodyError( + { + name: DataType.STRING, + date: DataType.DATETIME, + briefDescription: DataType.STRING, + ["fullDescription?"]: DataType.STRING, + }, + result.error + ) ); } diff --git a/src/Controllers/group.controllers.ts b/src/Controllers/group.controllers.ts index b902e95..686ed7a 100644 --- a/src/Controllers/group.controllers.ts +++ b/src/Controllers/group.controllers.ts @@ -5,7 +5,14 @@ import { z } from "zod"; import prisma from "../lib/prisma"; import { requireResponsibleForGroup } from "../Middleware/auth/auth"; 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 .object({ @@ -131,48 +138,47 @@ export const createGroup = async (req: Request<{ organisationPid: string }, {}, export const updateGroup = async (req: Request<{ pid: string }>, res: Response) => { const result = updateGroupBody.safeParse(req.body); - if(result.success === false){ - return res.status(400).json( - generateInvalidBodyError( - { - name: DataType.STRING, - user_limit: DataType.NUMBER, - level: DataType.NUMBER, - }, - result.error - ) - ); + if (result.success === false) { + return res.status(400).json( + generateInvalidBodyError( + { + name: DataType.STRING, + user_limit: DataType.NUMBER, + level: DataType.NUMBER, + }, + result.error + ) + ); } const body = result.data; const { pid } = req.params; - requireResponsibleForGroup(req.auth, pid) + requireResponsibleForGroup(req.auth, pid); try { - const group = await prisma.group.update({ - where: { pid }, - data: { - name: body.name, - user_limit: body.user_limit, - level: body.level, - }, - select: basicGroup, - }); - - res.status(200).json({ - type: "success", - payload: { group }, - }); - + const group = await prisma.group.update({ + where: { pid }, + data: { + name: body.name, + user_limit: body.user_limit, + level: body.level, + }, + select: basicGroup, + }); + + res.status(200).json({ + type: "success", + payload: { group }, + }); } catch (e) { - if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { - throw new NotFoundError("group", pid) - } - - throw e; + if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { + throw new NotFoundError("group", pid); + } + + throw e; } -} +}; interface DeleteGroupQueryParams { pid: string; @@ -191,7 +197,7 @@ export const deleteGroup = async (req: Request, res: Res return res.status(204).end(); } catch (e) { if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { - throw new NotFoundError("group", pid) + throw new NotFoundError("group", pid); } throw e; diff --git a/src/Controllers/role.controller.ts b/src/Controllers/role.controller.ts index 7995368..feff325 100644 --- a/src/Controllers/role.controller.ts +++ b/src/Controllers/role.controller.ts @@ -102,7 +102,7 @@ export const updateRoleScore = async (req: Request<{ pid: string }, {}, { score: const { score } = req.body; - if(typeof score !== "string"){ + if (typeof score !== "string") { res.status(400).json(generateInvalidBodyError({ score: DataType.STRING })); } @@ -115,40 +115,45 @@ export const updateRoleScore = async (req: Request<{ pid: string }, {}, { score: select: { pid: true, score: true, - schema: { select: { + schema: { + select: { pid: true, name: true, - } }, - participant: { select: { - pid: true, - firstName: true, - lastName: true, - } }, - team: { select: { - pid: true, - name: true, - }} - } + }, + }, + participant: { + select: { + pid: true, + firstName: true, + lastName: true, + }, + }, + team: { + select: { + pid: true, + name: true, + }, + }, + }, }); - + res.status(200).json({ type: "success", payload: { role, }, }); - } catch (e) { if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { - throw new NotFoundError("role", pid) + throw new NotFoundError("role", pid); } throw e; } -} +}; -export async function deleteRolesFromTeam(teamPid: string){ +export async function deleteRolesFromTeam(teamPid: string) { await prisma.role.deleteMany({ - where: { team: { pid: teamPid, } } + where: { team: { pid: teamPid } }, }); } diff --git a/src/Controllers/role_schema.controller.ts b/src/Controllers/role_schema.controller.ts index 4b8adda..f47e154 100644 --- a/src/Controllers/role_schema.controller.ts +++ b/src/Controllers/role_schema.controller.ts @@ -145,14 +145,17 @@ export const updateRoleSchema = async (req: Request<{ pid: string }>, res: Respo if (result.success === false) { return res.status(400).json( - generateInvalidBodyError({ - name: DataType.STRING, - schema: DataType.RESULT_SCHEMA, - }, result.error) + generateInvalidBodyError( + { + name: DataType.STRING, + schema: DataType.RESULT_SCHEMA, + }, + result.error + ) ); } - const {name, schema} = result.data; + const { name, schema } = result.data; const validatedSchema = parseSchema(schema); @@ -172,7 +175,7 @@ export const updateRoleSchema = async (req: Request<{ pid: string }>, res: Respo }); } catch (e) { if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { - throw new NotFoundError("roleSchema", pid) + throw new NotFoundError("roleSchema", pid); } throw e; @@ -197,7 +200,7 @@ export const deleteRoleSchema = async (req: Request<{ pid: string }>, res: Respo throw e; } -} +}; interface visualParams { schemaPid: string;