MOBILE-3565 core: Fix some ESLint of CoreConfigProvider
This commit is contained in:
		
							parent
							
								
									7a1342885b
								
							
						
					
					
						commit
						a2275ab52e
					
				@ -18,36 +18,38 @@ import { CoreApp, CoreAppSchema } from '@services/app';
 | 
				
			|||||||
import { SQLiteDB } from '@classes/sqlitedb';
 | 
					import { SQLiteDB } from '@classes/sqlitedb';
 | 
				
			||||||
import { makeSingleton } from '@singletons/core.singletons';
 | 
					import { makeSingleton } from '@singletons/core.singletons';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const TABLE_NAME = 'core_config';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Factory to provide access to dynamic and permanent config and settings.
 | 
					 * Factory to provide access to dynamic and permanent config and settings.
 | 
				
			||||||
 * It should not be abused into a temporary storage.
 | 
					 * It should not be abused into a temporary storage.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Injectable()
 | 
					@Injectable()
 | 
				
			||||||
export class CoreConfigProvider {
 | 
					export class CoreConfigProvider {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected appDB: SQLiteDB;
 | 
					    protected appDB: SQLiteDB;
 | 
				
			||||||
    protected TABLE_NAME = 'core_config';
 | 
					 | 
				
			||||||
    protected tableSchema: CoreAppSchema = {
 | 
					    protected tableSchema: CoreAppSchema = {
 | 
				
			||||||
        name: 'CoreConfigProvider',
 | 
					        name: 'CoreConfigProvider',
 | 
				
			||||||
        version: 1,
 | 
					        version: 1,
 | 
				
			||||||
        tables: [
 | 
					        tables: [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                name: this.TABLE_NAME,
 | 
					                name: TABLE_NAME,
 | 
				
			||||||
                columns: [
 | 
					                columns: [
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        name: 'name',
 | 
					                        name: 'name',
 | 
				
			||||||
                        type: 'TEXT',
 | 
					                        type: 'TEXT',
 | 
				
			||||||
                        unique: true,
 | 
					                        unique: true,
 | 
				
			||||||
                        notNull: true
 | 
					                        notNull: true,
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        name: 'value'
 | 
					                        name: 'value',
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected dbReady: Promise<any>; // Promise resolved when the app DB is initialized.
 | 
					    protected dbReady: Promise<void>; // Promise resolved when the app DB is initialized.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor() {
 | 
					    constructor() {
 | 
				
			||||||
        this.appDB = CoreApp.instance.getDB();
 | 
					        this.appDB = CoreApp.instance.getDB();
 | 
				
			||||||
@ -62,10 +64,10 @@ export class CoreConfigProvider {
 | 
				
			|||||||
     * @param name The config name.
 | 
					     * @param name The config name.
 | 
				
			||||||
     * @return Promise resolved when done.
 | 
					     * @return Promise resolved when done.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    async delete(name: string): Promise<any> {
 | 
					    async delete(name: string): Promise<void> {
 | 
				
			||||||
        await this.dbReady;
 | 
					        await this.dbReady;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return this.appDB.deleteRecords(this.TABLE_NAME, { name });
 | 
					        await this.appDB.deleteRecords(TABLE_NAME, { name });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -75,11 +77,11 @@ export class CoreConfigProvider {
 | 
				
			|||||||
     * @param defaultValue Default value to use if the entry is not found.
 | 
					     * @param defaultValue Default value to use if the entry is not found.
 | 
				
			||||||
     * @return Resolves upon success along with the config data. Reject on failure.
 | 
					     * @return Resolves upon success along with the config data. Reject on failure.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    async get(name: string, defaultValue?: any): Promise<any> {
 | 
					    async get<T>(name: string, defaultValue?: T): Promise<T> {
 | 
				
			||||||
        await this.dbReady;
 | 
					        await this.dbReady;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            const entry = await this.appDB.getRecord(this.TABLE_NAME, { name });
 | 
					            const entry = await this.appDB.getRecord(TABLE_NAME, { name });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return entry.value;
 | 
					            return entry.value;
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
@ -98,11 +100,12 @@ export class CoreConfigProvider {
 | 
				
			|||||||
     * @param value The config value. Can only store number or strings.
 | 
					     * @param value The config value. Can only store number or strings.
 | 
				
			||||||
     * @return Promise resolved when done.
 | 
					     * @return Promise resolved when done.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    async set(name: string, value: number | string): Promise<any> {
 | 
					    async set(name: string, value: number | string): Promise<void> {
 | 
				
			||||||
        await this.dbReady;
 | 
					        await this.dbReady;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return this.appDB.insertRecord(this.TABLE_NAME, { name, value });
 | 
					        await this.appDB.insertRecord(TABLE_NAME, { name, value });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class CoreConfig extends makeSingleton(CoreConfigProvider) {}
 | 
					export class CoreConfig extends makeSingleton(CoreConfigProvider) {}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user