From 7c66f31bac0b0ec25bc13f2dbb6e1e119b3ce0f6 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 27 Oct 2024 07:38:42 +0300 Subject: [PATCH] refactor: make compliance with the new api --- src/api/v1/faculty.service.ts | 5 -- src/services/token-refresh.service.ts | 82 ------------------- .../responses/v1/facultyDetailsResponse.ts | 37 --------- src/shared/responses/v1/facultyResponse.ts | 8 +- 4 files changed, 2 insertions(+), 130 deletions(-) delete mode 100644 src/services/token-refresh.service.ts delete mode 100644 src/shared/responses/v1/facultyDetailsResponse.ts diff --git a/src/api/v1/faculty.service.ts b/src/api/v1/faculty.service.ts index 013a085..b3bdcee 100644 --- a/src/api/v1/faculty.service.ts +++ b/src/api/v1/faculty.service.ts @@ -1,7 +1,6 @@ import {Injectable} from "@angular/core"; import ApiService, {AvailableVersion} from "@api/api.service"; import {FacultyResponse} from "@api/v1/facultyResponse"; -import {FacultyDetailsResponse} from "@api/v1/facultyDetailsResponse"; @Injectable() export class FacultyService extends ApiService { @@ -15,8 +14,4 @@ export class FacultyService extends ApiService { return this.get(request); } - - public getById(id: number) { - return this.get(id.toString()); - } } diff --git a/src/services/token-refresh.service.ts b/src/services/token-refresh.service.ts deleted file mode 100644 index f551967..0000000 --- a/src/services/token-refresh.service.ts +++ /dev/null @@ -1,82 +0,0 @@ -import {BehaviorSubject, catchError, of, Subject} from "rxjs"; -import {Injectable} from "@angular/core"; -import {AuthService} from "@service/auth.service"; -import {environment} from "@environment"; -import ApiService from "@api/api.service"; - -@Injectable({ - providedIn: 'root', -}) -export class TokenRefreshService { - private tokenRefreshing$ = new BehaviorSubject(false); - private refreshTokenTimeout: any; - private refreshTokenExpireMs: number = environment.retryDelay; - - constructor(private authService: AuthService) { - this.setRefreshTokenExpireMs(AuthService.tokenExpiresIn); - } - - private startTokenRefresh(): void { - this.refreshTokenTimeout = setTimeout(() => { - this.refreshToken(); - }, this.refreshTokenExpireMs); - } - - private refreshToken(): void { - if (this.tokenRefreshing$.value) - return; - - this.tokenRefreshing$.next(true); - - this.authService.refreshToken() - .pipe( - catchError(error => { - if (error.status === 403 || error.status === 401 || !localStorage.getItem(ApiService.tokenKey)) { - localStorage.removeItem(ApiService.tokenKey); - return of(undefined); - } - - let retryTime = this.refreshTokenExpireMs; - - if (retryTime < environment.retryDelay) - retryTime = environment.retryDelay; - - // 15 minutes - if (retryTime * 2 <= 900_000) - retryTime *= 2; - else - retryTime = 900_000; - - return of(retryTime); - })) - .subscribe(data => { - if (data) - this.setRefreshTokenExpireMs(data); - - this.tokenRefreshing$.next(false); - }); - } - - public getTokenRefreshing$(): Subject { - return this.tokenRefreshing$; - } - - public setRefreshTokenExpireMs(expireMs: number | string | Date | null = null): void { - let expireMsNumber: number; - if (expireMs === null) - expireMsNumber = -1; - else if (expireMs instanceof Date || typeof expireMs === 'string') - expireMsNumber = new Date(expireMs).getTime() - 1000 - Date.now(); - else - expireMsNumber = expireMs; - - if (expireMsNumber < environment.retryDelay) - expireMsNumber = environment.retryDelay; - - this.refreshTokenExpireMs = expireMsNumber; - console.log('New refresh token interval:', this.refreshTokenExpireMs); - - clearTimeout(this.refreshTokenTimeout); - this.startTokenRefresh(); - } -} diff --git a/src/shared/responses/v1/facultyDetailsResponse.ts b/src/shared/responses/v1/facultyDetailsResponse.ts deleted file mode 100644 index 550dc89..0000000 --- a/src/shared/responses/v1/facultyDetailsResponse.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * MIREA Schedule Web API - * This API provides a convenient interface for retrieving data stored in the database. Special attention was paid to the lightweight and easy transfer of all necessary data. Made by the Winsomnia team. - * - * OpenAPI spec version: 1.0 - * Contact: support@winsomnia.net - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ - -/** - * Represents detailed information about a faculty. - */ -export interface FacultyDetailsResponse { - /** - * Gets or sets the unique identifier of the faculty. - */ - id: number; - /** - * Gets or sets the name of the faculty. - */ - name: string; - /** - * Gets or sets the unique identifier of the campus to which the faculty belongs (optional). - */ - campusId?: number; - /** - * Gets or sets the name of the campus to which the faculty belongs (optional). - */ - campusName?: string; - /** - * Gets or sets the code name of the campus to which the faculty belongs (optional). - */ - campusCode?: string; -} \ No newline at end of file diff --git a/src/shared/responses/v1/facultyResponse.ts b/src/shared/responses/v1/facultyResponse.ts index 3865340..c8327c1 100644 --- a/src/shared/responses/v1/facultyResponse.ts +++ b/src/shared/responses/v1/facultyResponse.ts @@ -13,7 +13,7 @@ /** * Represents basic information about a faculty. */ -export interface FacultyResponse { +export interface FacultyResponse { /** * Gets or sets the unique identifier of the faculty. */ @@ -22,8 +22,4 @@ export interface FacultyResponse { * Gets or sets the name of the faculty. */ name: string; - /** - * Gets or sets the unique identifier of the campus to which the faculty belongs (optional). - */ - campusId?: number; -} \ No newline at end of file +}