fix(frontend): Linting errors/warnings opgelost
This commit is contained in:
parent
b2e6b33716
commit
4d98be78c1
26 changed files with 272 additions and 258 deletions
|
@ -9,40 +9,42 @@ export abstract class BaseController {
|
|||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
private assertSuccessResponse(response: AxiosResponse<unknown, unknown>) {
|
||||
private static assertSuccessResponse(response: AxiosResponse<unknown, unknown>): void {
|
||||
if (response.status / 100 !== 2) {
|
||||
throw new HttpErrorResponseException(response);
|
||||
}
|
||||
}
|
||||
|
||||
private absolutePathFor(path: string) {
|
||||
return "/" + this.basePath + path;
|
||||
}
|
||||
|
||||
protected async get<T>(path: string, queryParams?: Record<string, any>, responseType?: ResponseType): Promise<T> {
|
||||
let response = await apiClient.get<T>(
|
||||
protected async get<T>(path: string, queryParams?: QueryParams, responseType?: ResponseType): Promise<T> {
|
||||
const response = await apiClient.get<T>(
|
||||
this.absolutePathFor(path),
|
||||
{params: queryParams, responseType}
|
||||
);
|
||||
this.assertSuccessResponse(response);
|
||||
BaseController.assertSuccessResponse(response);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
protected async post<T>(path: string, body: unknown): Promise<T> {
|
||||
let response = await apiClient.post<T>(this.absolutePathFor(path), body);
|
||||
this.assertSuccessResponse(response);
|
||||
const response = await apiClient.post<T>(this.absolutePathFor(path), body);
|
||||
BaseController.assertSuccessResponse(response);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
protected async delete<T>(path: string): Promise<T> {
|
||||
let response = await apiClient.delete<T>(this.absolutePathFor(path))
|
||||
this.assertSuccessResponse(response);
|
||||
const response = await apiClient.delete<T>(this.absolutePathFor(path))
|
||||
BaseController.assertSuccessResponse(response);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
protected async put<T>(path: string, body: unknown): Promise<T> {
|
||||
let response = await apiClient.put<T>(this.absolutePathFor(path), body);
|
||||
this.assertSuccessResponse(response);
|
||||
const response = await apiClient.put<T>(this.absolutePathFor(path), body);
|
||||
BaseController.assertSuccessResponse(response);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
private absolutePathFor(path: string): string {
|
||||
return "/" + this.basePath + path;
|
||||
}
|
||||
}
|
||||
|
||||
type QueryParams = Record<string, string | number | boolean | undefined>;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {BaseController} from "@/controllers/base-controller.ts";
|
||||
import type {Language} from "@/data-objects/language.ts";
|
||||
import type {LearningObject} from "@/data-objects/learning-object.ts";
|
||||
import type {LearningObject} from "@/data-objects/learning-objects/learning-object.ts";
|
||||
|
||||
export class LearningObjectController extends BaseController {
|
||||
constructor() {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
import {BaseController} from "@/controllers/base-controller.ts";
|
||||
import {LearningPath} from "@/data-objects/learning-path.ts";
|
||||
import type {LearningPathDTO} from "@/data-objects/learning-path.ts";
|
||||
import {LearningPath} from "@/data-objects/learning-paths/learning-path.ts";
|
||||
import type {Language} from "@/data-objects/language.ts";
|
||||
import {single} from "@/utils/response-assertions.ts";
|
||||
import type {LearningPathDTO} from "@/data-objects/learning-paths/learning-path-dto.ts";
|
||||
|
||||
export class LearningPathController extends BaseController {
|
||||
constructor() {
|
||||
super("learningPath");
|
||||
}
|
||||
async search(query: string) {
|
||||
let dtos = await this.get<LearningPathDTO[]>("/", {search: query});
|
||||
async search(query: string): Promise<LearningPath[]> {
|
||||
const dtos = await this.get<LearningPathDTO[]>("/", {search: query});
|
||||
return dtos.map(dto => LearningPath.fromDTO(dto));
|
||||
}
|
||||
async getBy(hruid: string, language: Language, options?: {forGroup?: string, forStudent?: string}) {
|
||||
let dtos = await this.get<LearningPathDTO[]>("/", {
|
||||
async getBy(hruid: string, language: Language, options?: {forGroup?: string, forStudent?: string}): Promise<LearningPath> {
|
||||
const dtos = await this.get<LearningPathDTO[]>("/", {
|
||||
hruid,
|
||||
language,
|
||||
forGroup: options?.forGroup,
|
||||
|
@ -21,8 +21,8 @@ export class LearningPathController extends BaseController {
|
|||
});
|
||||
return LearningPath.fromDTO(single(dtos));
|
||||
}
|
||||
async getAllByTheme(theme: string) {
|
||||
let dtos = await this.get<LearningPathDTO[]>("/", {theme});
|
||||
async getAllByTheme(theme: string): Promise<LearningPath[]> {
|
||||
const dtos = await this.get<LearningPathDTO[]>("/", {theme});
|
||||
return dtos.map(dto => LearningPath.fromDTO(dto));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue