feat: (broken) POST method voor groep

This commit is contained in:
Adriaan Jacquet 2025-03-13 15:49:13 +01:00
parent 6ad0e990c7
commit 4c76a82178
6 changed files with 81 additions and 7 deletions

View file

@ -1,5 +1,6 @@
import { Request, Response } from 'express';
import { getAllGroups, getGroup, getGroupSubmissions } from '../services/groups.js';
import { createGroup, getAllGroups, getGroup, getGroupSubmissions } from '../services/groups.js';
import { GroupDTO } from '../interfaces/group.js';
// Typescript is annoywith with parameter forwarding from class.ts
interface GroupParams {
@ -54,6 +55,29 @@ export async function getAllGroupsHandler(
});
}
export async function createGroupHandler(
req: Request,
res: Response,
): Promise<void> {
const classid = req.params.classid;
const assignmentId = +req.params.assignmentid;
if (isNaN(assignmentId)) {
res.status(400).json({ error: 'Assignment id must be a number' });
return;
}
const groupData = req.body as GroupDTO;
const group = createGroup(groupData, classid, assignmentId);
if (!group) {
res.status(500).json({ error: "Something went wrong while creating group" });
return
}
res.status(201).json({ group: group });
}
export async function getGroupSubmissionsHandler(
req: Request,
res: Response,