refactor(backend): no-implicit-coercion
This commit is contained in:
parent
65c1a5e6b6
commit
10d3d0567e
5 changed files with 12 additions and 12 deletions
|
@ -41,7 +41,7 @@ export async function createAssignmentHandler(req: Request<AssignmentParams>, re
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
export async function getAssignmentHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
||||||
const id = +req.params.id;
|
const id = Number(req.params.id);
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
|
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
|
@ -61,7 +61,7 @@ export async function getAssignmentHandler(req: Request<AssignmentParams>, res:
|
||||||
|
|
||||||
export async function getAssignmentsSubmissionsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
export async function getAssignmentsSubmissionsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
const assignmentNumber = +req.params.id;
|
const assignmentNumber = Number(req.params.id);
|
||||||
|
|
||||||
if (isNaN(assignmentNumber)) {
|
if (isNaN(assignmentNumber)) {
|
||||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||||
|
|
|
@ -12,14 +12,14 @@ interface GroupParams {
|
||||||
export async function getGroupHandler(req: Request<GroupParams>, res: Response): Promise<void> {
|
export async function getGroupHandler(req: Request<GroupParams>, res: Response): Promise<void> {
|
||||||
const classId = req.params.classid;
|
const classId = req.params.classid;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
const assignmentId = +req.params.assignmentid;
|
const assignmentId = Number(req.params.assignmentid);
|
||||||
|
|
||||||
if (isNaN(assignmentId)) {
|
if (isNaN(assignmentId)) {
|
||||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupId = +req.params.groupid!; // Can't be undefined
|
const groupId = Number(req.params.groupid!); // Can't be undefined
|
||||||
|
|
||||||
if (isNaN(groupId)) {
|
if (isNaN(groupId)) {
|
||||||
res.status(400).json({ error: 'Group id must be a number' });
|
res.status(400).json({ error: 'Group id must be a number' });
|
||||||
|
@ -35,7 +35,7 @@ export async function getAllGroupsHandler(req: Request, res: Response): Promise<
|
||||||
const classId = req.params.classid;
|
const classId = req.params.classid;
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
||||||
const assignmentId = +req.params.assignmentid;
|
const assignmentId = Number(req.params.assignmentid);
|
||||||
|
|
||||||
if (isNaN(assignmentId)) {
|
if (isNaN(assignmentId)) {
|
||||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||||
|
@ -51,7 +51,7 @@ export async function getAllGroupsHandler(req: Request, res: Response): Promise<
|
||||||
|
|
||||||
export async function createGroupHandler(req: Request, res: Response): Promise<void> {
|
export async function createGroupHandler(req: Request, res: Response): Promise<void> {
|
||||||
const classid = req.params.classid;
|
const classid = req.params.classid;
|
||||||
const assignmentId = +req.params.assignmentid;
|
const assignmentId = Number(req.params.assignmentid);
|
||||||
|
|
||||||
if (isNaN(assignmentId)) {
|
if (isNaN(assignmentId)) {
|
||||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||||
|
@ -73,14 +73,14 @@ export async function getGroupSubmissionsHandler(req: Request, res: Response): P
|
||||||
const classId = req.params.classid;
|
const classId = req.params.classid;
|
||||||
// Const full = req.query.full === 'true';
|
// Const full = req.query.full === 'true';
|
||||||
|
|
||||||
const assignmentId = +req.params.assignmentid;
|
const assignmentId = Number(req.params.assignmentid);
|
||||||
|
|
||||||
if (isNaN(assignmentId)) {
|
if (isNaN(assignmentId)) {
|
||||||
res.status(400).json({ error: 'Assignment id must be a number' });
|
res.status(400).json({ error: 'Assignment id must be a number' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupId = +req.params.groupid!; // Can't be undefined
|
const groupId = Number(req.params.groupid!); // Can't be undefined
|
||||||
|
|
||||||
if (isNaN(groupId)) {
|
if (isNaN(groupId)) {
|
||||||
res.status(400).json({ error: 'Group id must be a number' });
|
res.status(400).json({ error: 'Group id must be a number' });
|
||||||
|
|
|
@ -17,7 +17,7 @@ function getObjectId(req: Request, res: Response): LearningObjectIdentifier | nu
|
||||||
return {
|
return {
|
||||||
hruid,
|
hruid,
|
||||||
language: (lang as Language) || FALLBACK_LANG,
|
language: (lang as Language) || FALLBACK_LANG,
|
||||||
version: +version,
|
version: Number(version),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface SubmissionParams {
|
||||||
|
|
||||||
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
|
export async function getSubmissionHandler(req: Request<SubmissionParams>, res: Response): Promise<void> {
|
||||||
const lohruid = req.params.hruid;
|
const lohruid = req.params.hruid;
|
||||||
const submissionNumber = +req.params.id;
|
const submissionNumber = Number(req.params.id);
|
||||||
|
|
||||||
if (isNaN(submissionNumber)) {
|
if (isNaN(submissionNumber)) {
|
||||||
res.status(400).json({ error: 'Submission number is not a number' });
|
res.status(400).json({ error: 'Submission number is not a number' });
|
||||||
|
@ -44,7 +44,7 @@ export async function createSubmissionHandler(req: Request, res: Response): Prom
|
||||||
|
|
||||||
export async function deleteSubmissionHandler(req: Request, res: Response): Promise<void> {
|
export async function deleteSubmissionHandler(req: Request, res: Response): Promise<void> {
|
||||||
const hruid = req.params.hruid;
|
const hruid = req.params.hruid;
|
||||||
const submissionNumber = +req.params.id;
|
const submissionNumber = Number(req.params.id);
|
||||||
|
|
||||||
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
const lang = languageMap[req.query.language as string] || Language.Dutch;
|
||||||
const version = (req.query.version || 1) as number;
|
const version = (req.query.version || 1) as number;
|
||||||
|
|
|
@ -152,7 +152,7 @@ function convertTransition(
|
||||||
throw new Error(`Learning object ${transition.next.learningObjectHruid}/${transition.next.language}/${transition.next.version} not found!`);
|
throw new Error(`Learning object ${transition.next.learningObjectHruid}/${transition.next.language}/${transition.next.version} not found!`);
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
_id: '' + index, // Retained for backwards compatibility. The index uniquely identifies the transition within the learning path.
|
_id: String(index), // Retained for backwards compatibility. The index uniquely identifies the transition within the learning path.
|
||||||
default: false, // We don't work with default transitions but retain this for backwards compatibility.
|
default: false, // We don't work with default transitions but retain this for backwards compatibility.
|
||||||
next: {
|
next: {
|
||||||
_id: nextNode._id + index, // Construct a unique ID for the transition for backwards compatibility.
|
_id: nextNode._id + index, // Construct a unique ID for the transition for backwards compatibility.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue