refactor: enum voor account types

This commit is contained in:
Gabriellvl 2025-05-15 20:54:43 +02:00
parent f9fc19d8a6
commit fc0d3b5c84
20 changed files with 77 additions and 5870 deletions

View file

@ -2,6 +2,7 @@ import { authorize } from './auth-checks.js';
import { fetchClass } from '../../../services/classes.js';
import { fetchGroup } from '../../../services/groups.js';
import { mapToUsername } from '../../../interfaces/user.js';
import {AccountType} from "@dwengo-1/common/util/account-types";
/**
* Expects the path to contain the path parameters 'classid', 'assignmentid' and 'groupid'.
@ -16,7 +17,7 @@ export const onlyAllowIfHasAccessToGroup = authorize(async (auth, req) => {
groupid: groupId,
} = req.params as { classid: string; assignmentid: number; groupid: number };
if (auth.accountType === 'teacher') {
if (auth.accountType === AccountType.Teacher) {
const clazz = await fetchClass(classId);
return clazz.teachers.map(mapToUsername).includes(auth.username);
} // User is student