added function to delete unverified teams

This commit is contained in:
La_Felx
2023-01-03 22:34:30 +01:00
parent a1a0bca5a1
commit e8c7dfc5e6
2 changed files with 25 additions and 1 deletions
+19
View File
@@ -150,6 +150,14 @@ export const deleteTeam = async (req: Request, res: Response) => {
} }
}; };
export const deleteUnverifiedTeams =async (req: Request, res: Response) => {
const { pid } = req.params;
await _deleteUnverifiedTeams(pid);
res.status(204).end();
}
export async function checkTeamExistence(teamPid: string) { export async function checkTeamExistence(teamPid: string) {
const teamCount = await prisma.team.count({ const teamCount = await prisma.team.count({
where: { pid: teamPid }, where: { pid: teamPid },
@@ -173,3 +181,14 @@ export async function getGroupsByTeamPid(teamPid: string) {
return groups; return groups;
}; };
export async function _deleteUnverifiedTeams(eventPid: string) {
await prisma.team.deleteMany({
where: {
AND: [{discipline: {event: {pid: eventPid}}},
{verified: {equals: false}}
]
}
});
};
+6 -1
View File
@@ -1,6 +1,6 @@
import express from "express"; import express from "express";
import { requireConfiguredAuthentication } from "../Middleware/auth/auth"; import { requireConfiguredAuthentication } from "../Middleware/auth/auth";
import { deleteTeam, getTeam, getTeams, updateTeam } from "../Controllers/team.controller"; import { deleteTeam, deleteUnverifiedTeams, getTeam, getTeams, updateTeam } from "../Controllers/team.controller";
import { getRolesForTeam } from "../Controllers/role.controller"; import { getRolesForTeam } from "../Controllers/role.controller";
const router = express.Router(); const router = express.Router();
@@ -22,5 +22,10 @@ router.delete<"/:pid/", { pid: string }>(
requireConfiguredAuthentication({ optional: false, type: { admin: true, teamleader: true } }), requireConfiguredAuthentication({ optional: false, type: { admin: true, teamleader: true } }),
deleteTeam deleteTeam
); );
router.delete<"/:pid/deleteUnverified/", {pid: string}>(
"/:pid/deleteUnverified/",
requireConfiguredAuthentication({optional: false, type: "admin"}),
deleteUnverifiedTeams
);
export default router; export default router;