refactor(backend): File has too many classes
This commit is contained in:
parent
25f9eb2af2
commit
5b31cec5fe
15 changed files with 87 additions and 67 deletions
|
@ -4,7 +4,7 @@ import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifie
|
|||
import learningObjectService from '../services/learning-objects/learning-object-service.js';
|
||||
import { envVars, getEnvVar } from '../util/envVars.js';
|
||||
import { Language } from '../entities/content/language.js';
|
||||
import { BadRequestException } from '../exceptions.js';
|
||||
import { BadRequestException } from '../exceptions/badRequestException.js';
|
||||
import attachmentService from '../services/learning-objects/attachment-service.js';
|
||||
import { NotFoundError } from '@mikro-orm/core';
|
||||
|
||||
|
|
|
@ -2,13 +2,14 @@ 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.js';
|
||||
import { BadRequestException, NotFoundException } from '../exceptions.js';
|
||||
import { BadRequestException } from '../exceptions/badRequestException.js';
|
||||
import { Language } from '../entities/content/language.js';
|
||||
import {
|
||||
PersonalizationTarget,
|
||||
personalizedForGroup,
|
||||
personalizedForStudent,
|
||||
} from '../services/learning-paths/learning-path-personalization-util.js';
|
||||
import { NotFoundException } from '../exceptions/notFoundException.js';
|
||||
|
||||
/**
|
||||
* Fetch learning paths based on query parameters.
|
||||
|
|
10
backend/src/entities/content/educational-goal.entity.ts
Normal file
10
backend/src/entities/content/educational-goal.entity.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { Embeddable, Property } from '@mikro-orm/core';
|
||||
|
||||
@Embeddable()
|
||||
export class EducationalGoal {
|
||||
@Property({ type: 'string' })
|
||||
source!: string;
|
||||
|
||||
@Property({ type: 'string' })
|
||||
id!: string;
|
||||
}
|
|
@ -1,28 +1,12 @@
|
|||
import { Embeddable, Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Language } from './language.js';
|
||||
import { Attachment } from './attachment.entity.js';
|
||||
import { Teacher } from '../users/teacher.entity.js';
|
||||
import { DwengoContentType } from '../../services/learning-objects/processing/content-type.js';
|
||||
import { v4 } from 'uuid';
|
||||
import { LearningObjectRepository } from '../../data/content/learning-object-repository.js';
|
||||
|
||||
@Embeddable()
|
||||
export class EducationalGoal {
|
||||
@Property({ type: 'string' })
|
||||
source!: string;
|
||||
|
||||
@Property({ type: 'string' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Embeddable()
|
||||
export class ReturnValue {
|
||||
@Property({ type: 'string' })
|
||||
callbackUrl!: string;
|
||||
|
||||
@Property({ type: 'json' })
|
||||
callbackSchema!: string;
|
||||
}
|
||||
import { EducationalGoal } from './educational-goal.entity.js';
|
||||
import { ReturnValue } from './return-value.entity.js';
|
||||
|
||||
@Entity({ repository: () => LearningObjectRepository })
|
||||
export class LearningObject {
|
||||
|
|
10
backend/src/entities/content/return-value.entity.ts
Normal file
10
backend/src/entities/content/return-value.entity.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { Embeddable, Property } from '@mikro-orm/core';
|
||||
|
||||
@Embeddable()
|
||||
export class ReturnValue {
|
||||
@Property({ type: 'string' })
|
||||
callbackUrl!: string;
|
||||
|
||||
@Property({ type: 'json' })
|
||||
callbackSchema!: string;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/**
|
||||
* Exception for HTTP 400 Bad Request
|
||||
*/
|
||||
export class BadRequestException extends Error {
|
||||
public status = 400;
|
||||
|
||||
constructor(error: string) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception for HTTP 401 Unauthorized
|
||||
*/
|
||||
export class UnauthorizedException extends Error {
|
||||
status = 401;
|
||||
constructor(message: string = 'Unauthorized') {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception for HTTP 403 Forbidden
|
||||
*/
|
||||
export class ForbiddenException extends Error {
|
||||
status = 403;
|
||||
|
||||
constructor(message: string = 'Forbidden') {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception for HTTP 404 Not Found
|
||||
*/
|
||||
export class NotFoundException extends Error {
|
||||
public status = 404;
|
||||
|
||||
constructor(error: string) {
|
||||
super(error);
|
||||
}
|
||||
}
|
11
backend/src/exceptions/badRequestException.ts
Normal file
11
backend/src/exceptions/badRequestException.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { HttpException } from './httpException.js';
|
||||
|
||||
/**
|
||||
* Exception for HTTP 400 Bad Request
|
||||
*/
|
||||
|
||||
export class BadRequestException extends HttpException {
|
||||
constructor(message: string = 'Bad Request') {
|
||||
super(400, message);
|
||||
}
|
||||
}
|
10
backend/src/exceptions/forbiddenException.ts
Normal file
10
backend/src/exceptions/forbiddenException.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { HttpException } from './httpException.js';
|
||||
|
||||
/**
|
||||
* Exception for HTTP 403 Forbidden
|
||||
*/
|
||||
export class ForbiddenException extends HttpException {
|
||||
constructor(message: string = 'Forbidden') {
|
||||
super(403, message);
|
||||
}
|
||||
}
|
8
backend/src/exceptions/httpException.ts
Normal file
8
backend/src/exceptions/httpException.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
export class HttpException extends Error {
|
||||
constructor(
|
||||
public status: number,
|
||||
message: string
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
10
backend/src/exceptions/notFoundException.ts
Normal file
10
backend/src/exceptions/notFoundException.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { HttpException } from './httpException.js';
|
||||
|
||||
/**
|
||||
* Exception for HTTP 404 Not Found
|
||||
*/
|
||||
export class NotFoundException extends HttpException {
|
||||
constructor(message: string = 'Not Found') {
|
||||
super(404, message);
|
||||
}
|
||||
}
|
10
backend/src/exceptions/unauthorizedException.ts
Normal file
10
backend/src/exceptions/unauthorizedException.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { HttpException } from './httpException.js';
|
||||
|
||||
/**
|
||||
* Exception for HTTP 401 Unauthorized
|
||||
*/
|
||||
export class UnauthorizedException extends HttpException {
|
||||
constructor(message: string = 'Unauthorized') {
|
||||
super(401, message);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,8 @@ import jwksClient from 'jwks-rsa';
|
|||
import * as express from 'express';
|
||||
import { AuthenticatedRequest } from './authenticated-request.js';
|
||||
import { AuthenticationInfo } from './authentication-info.js';
|
||||
import { ForbiddenException, UnauthorizedException } from '../../exceptions.js';
|
||||
import { UnauthorizedException } from '../../exceptions/unauthorizedException.js';
|
||||
import { ForbiddenException } from '../../exceptions/forbiddenException.js';
|
||||
|
||||
const JWKS_CACHE = true;
|
||||
const JWKS_RATE_LIMIT = true;
|
||||
|
|
|
@ -5,7 +5,11 @@ const STUDENT_IDP_PREFIX = IDP_PREFIX + 'STUDENT_';
|
|||
const TEACHER_IDP_PREFIX = IDP_PREFIX + 'TEACHER_';
|
||||
const CORS_PREFIX = PREFIX + 'CORS_';
|
||||
|
||||
interface EnvVar { key: string; required?: boolean; defaultValue?: number | string | boolean }
|
||||
interface EnvVar {
|
||||
key: string;
|
||||
required?: boolean;
|
||||
defaultValue?: number | string | boolean;
|
||||
}
|
||||
|
||||
export const envVars: { [key: string]: EnvVar } = {
|
||||
Port: { key: PREFIX + 'PORT', defaultValue: 3000 },
|
||||
|
|
|
@ -2,9 +2,11 @@ import { LearningObjectExample } from '../learning-object-example';
|
|||
import { Language } from '../../../../src/entities/content/language';
|
||||
import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type';
|
||||
import { loadTestAsset } from '../../../test-utils/load-test-asset';
|
||||
import { EducationalGoal, LearningObject, ReturnValue } from '../../../../src/entities/content/learning-object.entity';
|
||||
import { LearningObject } from '../../../../src/entities/content/learning-object.entity';
|
||||
import { Attachment } from '../../../../src/entities/content/attachment.entity';
|
||||
import { envVars, getEnvVar } from '../../../../src/util/envVars';
|
||||
import { EducationalGoal } from '../../../../src/entities/content/educational-goal.entity';
|
||||
import { ReturnValue } from '../../../../src/entities/content/return-value.entity';
|
||||
|
||||
const ASSETS_PREFIX = 'learning-objects/pn-werkingnotebooks/';
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { EntityManager } from '@mikro-orm/core';
|
||||
import { LearningObject, ReturnValue } from '../../../src/entities/content/learning-object.entity';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
|
||||
import { Language } from '../../../src/entities/content/language';
|
||||
import { DwengoContentType } from '../../../src/services/learning-objects/processing/content-type';
|
||||
import { ReturnValue } from '../../../src/entities/content/return-value.entity';
|
||||
|
||||
export function makeTestLearningObjects(em: EntityManager): Array<LearningObject> {
|
||||
const returnValue: ReturnValue = new ReturnValue();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue