style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-11 03:09:12 +00:00
parent aa1a85e64e
commit 2a2881ec30
84 changed files with 846 additions and 1013 deletions

View file

@ -1,38 +1,35 @@
import { Request, Response } from 'express';
import { FALLBACK_LANG } from '../config.js';
import {FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier} from '../interfaces/learning-content';
import learningObjectService from "../services/learning-objects/learning-object-service";
import {EnvVars, getEnvVar} from "../util/envvars";
import {Language} from "../entities/content/language";
import {BadRequestException} from "../exceptions";
import attachmentService from "../services/learning-objects/attachment-service";
import {NotFoundError} from "@mikro-orm/core";
import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from '../interfaces/learning-content';
import learningObjectService from '../services/learning-objects/learning-object-service';
import { EnvVars, getEnvVar } from '../util/envvars';
import { Language } from '../entities/content/language';
import { BadRequestException } from '../exceptions';
import attachmentService from '../services/learning-objects/attachment-service';
import { NotFoundError } from '@mikro-orm/core';
function getLearningObjectIdentifierFromRequest(req: Request): LearningObjectIdentifier {
if (!req.params.hruid) {
throw new BadRequestException("HRUID is required.");
throw new BadRequestException('HRUID is required.');
}
return {
hruid: req.params.hruid as string,
language: (req.query.language || getEnvVar(EnvVars.FallbackLanguage)) as Language,
version: parseInt(req.query.version as string)
version: parseInt(req.query.version as string),
};
}
function getLearningPathIdentifierFromRequest(req: Request): LearningPathIdentifier {
if (!req.query.hruid) {
throw new BadRequestException("HRUID is required.");
throw new BadRequestException('HRUID is required.');
}
return {
hruid: req.params.hruid as string,
language: (req.query.language as Language) || FALLBACK_LANG
}
language: (req.query.language as Language) || FALLBACK_LANG,
};
}
export async function getAllLearningObjects(
req: Request,
res: Response
): Promise<void> {
export async function getAllLearningObjects(req: Request, res: Response): Promise<void> {
const learningPathId = getLearningPathIdentifierFromRequest(req);
const full = req.query.full;
@ -46,10 +43,7 @@ export async function getAllLearningObjects(
res.json(learningObjects);
}
export async function getLearningObject(
req: Request,
res: Response
): Promise<void> {
export async function getLearningObject(req: Request, res: Response): Promise<void> {
const learningObjectId = getLearningObjectIdentifierFromRequest(req);
const learningObject = await learningObjectService.getLearningObjectById(learningObjectId);
@ -71,5 +65,5 @@ export async function getAttachment(req: Request, res: Response): Promise<void>
if (!attachment) {
throw new NotFoundError(`Attachment ${name} not found`);
}
res.setHeader("Content-Type", attachment.mimeType).send(attachment.content)
res.setHeader('Content-Type', attachment.mimeType).send(attachment.content);
}

View file

@ -1,16 +1,13 @@
import { Request, Response } from 'express';
import { themes } from '../data/themes.js';
import { FALLBACK_LANG } from '../config.js';
import learningPathService from "../services/learning-paths/learning-path-service";
import {NotFoundException} from "../exceptions";
import learningPathService from '../services/learning-paths/learning-path-service';
import { NotFoundException } from '../exceptions';
/**
* Fetch learning paths based on query parameters.
*/
export async function getLearningPaths(
req: Request,
res: Response
): Promise<void> {
export async function getLearningPaths(req: Request, res: Response): Promise<void> {
const hruids = req.query.hruid;
const themeKey = req.query.theme as string;
const searchQuery = req.query.search as string;
@ -19,9 +16,7 @@ export async function getLearningPaths(
let hruidList;
if (hruids) {
hruidList = Array.isArray(hruids)
? hruids.map(String)
: [String(hruids)];
hruidList = Array.isArray(hruids) ? hruids.map(String) : [String(hruids)];
} else if (themeKey) {
const theme = themes.find((t) => t.title === themeKey);
if (theme) {
@ -30,20 +25,13 @@ export async function getLearningPaths(
throw new NotFoundException(`Theme "${themeKey}" not found.`);
}
} else if (searchQuery) {
const searchResults = await learningPathService.searchLearningPaths(
searchQuery,
language
);
const searchResults = await learningPathService.searchLearningPaths(searchQuery, language);
res.json(searchResults);
return;
} else {
hruidList = themes.flatMap((theme) => theme.hruids);
}
const learningPaths = await learningPathService.fetchLearningPaths(
hruidList,
language,
`HRUIDs: ${hruidList.join(', ')}`
);
const learningPaths = await learningPathService.fetchLearningPaths(hruidList, language, `HRUIDs: ${hruidList.join(', ')}`);
res.json(learningPaths.data);
}

View file

@ -1,4 +1,3 @@
import { Request, Response } from 'express';
import { themes } from '../data/themes.js';
import { FALLBACK_LANG } from '../config.js';