feat: (broken) POST method voor groep
This commit is contained in:
parent
6ad0e990c7
commit
4c76a82178
6 changed files with 81 additions and 7 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue