mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-03 03:52:52 +00:00
Resolve "Read library account URLs from the backend"
This commit is contained in:
@@ -1,53 +1,63 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
// import {ConfigProvider} from '../../config/config.provider';
|
||||
import {PAIAAuthService} from '../../auth/paia/paia-auth.service';
|
||||
import {JQueryRequestor, Requestor} from '@openid/appauth';
|
||||
import {SCFeatureConfigurationExtern, SCMap} from '@openstapps/core';
|
||||
import {
|
||||
SCAuthorizationProviderType,
|
||||
SCFeatureConfiguration,
|
||||
SCFeatureConfigurationExtern,
|
||||
} from '@openstapps/core';
|
||||
import {PAIADocumentStatus, PAIAFees, PAIAItems, PAIAPatron} from '../types';
|
||||
import {HebisDataProvider} from '../../hebis/hebis-data.provider';
|
||||
import {ConfigProvider} from '../../config/config.provider';
|
||||
import {AuthHelperService} from '../../auth/auth-helper.service';
|
||||
import {PAIATokenResponse} from '../../auth/paia/paia-token-response';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LibraryAccountService {
|
||||
// TODO: must come from backend (not that stable)
|
||||
private _config: SCMap<SCFeatureConfigurationExtern> = {
|
||||
profile: {
|
||||
url: 'https://hds.hebis.de:8443/core/{patron}',
|
||||
},
|
||||
items: {
|
||||
url: 'https://hds.hebis.de:8443/core/{patron}/items',
|
||||
},
|
||||
fees: {
|
||||
url: 'https://hds.hebis.de:8443/core/{patron}/fees',
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Base url of the external service
|
||||
*/
|
||||
baseUrl: string;
|
||||
|
||||
/**
|
||||
* Authorization provider type
|
||||
*/
|
||||
authType: SCAuthorizationProviderType;
|
||||
|
||||
constructor(
|
||||
protected requestor: Requestor = new JQueryRequestor(),
|
||||
private readonly paiaAuth: PAIAAuthService,
|
||||
private readonly hebisDataProvider: HebisDataProvider,
|
||||
) {}
|
||||
|
||||
get config() {
|
||||
return this._config;
|
||||
private readonly authHelper: AuthHelperService,
|
||||
readonly configProvider: ConfigProvider,
|
||||
) {
|
||||
const config: SCFeatureConfigurationExtern = (
|
||||
configProvider.getValue('features') as SCFeatureConfiguration
|
||||
).extern!.paia;
|
||||
this.baseUrl = config.url;
|
||||
this.authType = config.authProvider as SCAuthorizationProviderType;
|
||||
}
|
||||
|
||||
async getProfile() {
|
||||
return this.performRequest<PAIAPatron>(this.config.profile.url);
|
||||
return this.performRequest<PAIAPatron>(`${this.baseUrl}/{patron}`);
|
||||
}
|
||||
|
||||
async getItems() {
|
||||
return this.performRequest<PAIAItems>(this.config.items.url);
|
||||
return this.performRequest<PAIAItems>(`${this.baseUrl}/{patron}/items`);
|
||||
}
|
||||
|
||||
async getFees() {
|
||||
return this.performRequest<PAIAFees>(this.config.fees.url);
|
||||
return this.performRequest<PAIAFees>(`${this.baseUrl}/{patron}/fees`);
|
||||
}
|
||||
|
||||
private async performRequest<T>(urlTemplate: string): Promise<T> {
|
||||
const token = await this.paiaAuth.getValidToken();
|
||||
const url = urlTemplate.replace('{patron}', token.patron);
|
||||
const token = await this.authHelper
|
||||
.getProvider(this.authType)
|
||||
.getValidToken();
|
||||
const url = urlTemplate.replace(
|
||||
'{patron}',
|
||||
(token as PAIATokenResponse).patron,
|
||||
);
|
||||
const settings: JQueryAjaxSettings = {
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
|
||||
Reference in New Issue
Block a user