mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
fix: update core and apply stricter tslint rules
This commit is contained in:
@@ -24,41 +24,64 @@ export enum DataScope {
|
||||
Remote = 'remote',
|
||||
}
|
||||
|
||||
/*
|
||||
Generated class for the DataProvider provider.
|
||||
|
||||
See https://angular.io/guide/dependency-injection for more info on providers
|
||||
and Angular DI.
|
||||
*/
|
||||
/**
|
||||
* Generated class for the DataProvider provider.
|
||||
*
|
||||
* See https://angular.io/guide/dependency-injection for more info on providers
|
||||
* and Angular DI.
|
||||
*/
|
||||
@Injectable()
|
||||
export class DataProvider {
|
||||
private _storagePrefix: string = 'stapps.data';
|
||||
// @TODO: get backendUrl and appVersion and storagePrefix from config (module)
|
||||
appVersion: string = '1.0.6';
|
||||
backendUrl: string = 'http://localhost:3000';
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
private _storagePrefix = 'stapps.data';
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @TODO: get backendUrl and appVersion and storagePrefix from config (module)
|
||||
*/
|
||||
appVersion = '1.0.6';
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
backendUrl = 'http://localhost:3000';
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
client: Client;
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
storageProvider: StorageProvider;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @param stAppsWebHttpClient TODO
|
||||
* @param storageProvider TODO
|
||||
*/
|
||||
constructor(stAppsWebHttpClient: StAppsWebHttpClient, storageProvider: StorageProvider) {
|
||||
this.client = new Client(stAppsWebHttpClient, this.backendUrl, this.appVersion);
|
||||
this.storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
get storagePrefix(): string {
|
||||
return this._storagePrefix;
|
||||
}
|
||||
|
||||
set storagePrefix(storagePrefix) {
|
||||
this._storagePrefix = storagePrefix;
|
||||
/**
|
||||
* Delete a data item
|
||||
*
|
||||
* @param uid Unique identifier of the saved data item
|
||||
*/
|
||||
async delete(uid: string): Promise<void> {
|
||||
return this.storageProvider.delete(this.getDataKey(uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides key for storing data into the local database
|
||||
*
|
||||
* @param uid Unique identifier of a resource
|
||||
* Delete all the previously saved data items
|
||||
*/
|
||||
getDataKey(uid: string): string {
|
||||
return `${this.storagePrefix}.${uid}`;
|
||||
async deleteAll(): Promise<void> {
|
||||
const keys = Array.from((await this.getAll()).keys());
|
||||
|
||||
return this.storageProvider.delete(...keys);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,6 +114,7 @@ export class DataProvider {
|
||||
const map: Map<DataScope, SCThings | SCSaveableThing<SCThings>> = new Map();
|
||||
map.set(DataScope.Local, await this.get(uid, DataScope.Local));
|
||||
map.set(DataScope.Remote, await this.get(uid, DataScope.Remote));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -101,6 +125,24 @@ export class DataProvider {
|
||||
return this.storageProvider.search<SCSaveableThing<SCThings>>(this.storagePrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides key for storing data into the local database
|
||||
*
|
||||
* @param uid Unique identifier of a resource
|
||||
*/
|
||||
getDataKey(uid: string): string {
|
||||
return `${this.storagePrefix}.${uid}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides information if something with an UID is saved as a data item
|
||||
*
|
||||
* @param uid Unique identifier of the saved data item
|
||||
*/
|
||||
async isSaved(uid: string): Promise<boolean> {
|
||||
return this.storageProvider.has(this.getDataKey(uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a data item
|
||||
*
|
||||
@@ -118,25 +160,9 @@ export class DataProvider {
|
||||
type: (typeof type === 'undefined') ? item.type : type,
|
||||
uid: item.uid,
|
||||
};
|
||||
|
||||
// @TODO: Implementation for saving item into the backend (user's account)
|
||||
return (await this.storageProvider.put<SCSaveableThing<SCThings>>(this.getDataKey(item.uid), saveableItem));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a data item
|
||||
*
|
||||
* @param uid Unique identifier of the saved data item
|
||||
*/
|
||||
async delete(uid: string): Promise<void> {
|
||||
return this.storageProvider.delete(this.getDataKey(uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the previously saved data items
|
||||
*/
|
||||
async deleteAll(): Promise<void> {
|
||||
const keys = Array.from((await this.getAll()).keys());
|
||||
return this.storageProvider.delete(...keys);
|
||||
return ( this.storageProvider.put<SCSaveableThing<SCThings>>(this.getDataKey(item.uid), saveableItem));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,15 +171,20 @@ export class DataProvider {
|
||||
* @param query - query to send to the backend
|
||||
*/
|
||||
async search(query: SCSearchQuery): Promise<SCSearchResponse> {
|
||||
return (await this.client.search(query));
|
||||
return (this.client.search(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides information if something with an UID is saved as a data item
|
||||
*
|
||||
* @param uid Unique identifier of the saved data item
|
||||
* TODO
|
||||
*/
|
||||
async isSaved(uid: string): Promise<boolean> {
|
||||
return this.storageProvider.has(this.getDataKey(uid));
|
||||
get storagePrefix(): string {
|
||||
return this._storagePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
set storagePrefix(storagePrefix) {
|
||||
this._storagePrefix = storagePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user