From 85cb069e9bc28252fdfdce1c05f17f6111473bed Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 29 Dec 2019 00:53:58 +0100 Subject: [PATCH] :bug: (database) fix init local database --- src/services/CouchService.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/services/CouchService.ts b/src/services/CouchService.ts index 0c95634..5fbe9f7 100644 --- a/src/services/CouchService.ts +++ b/src/services/CouchService.ts @@ -23,7 +23,7 @@ const LOCALE_DB: string = 'VAQUANT_LOCALE_DB' const REMOTE: string = 'https://juliencalixte.ddns.net/database' class CouchService { - public db: PouchDB.Database | null = new PouchDb(LOCALE_DB) + public db: PouchDB.Database | null = null private innerRemote: PouchDB.Database | null = null private user: IUser | null = null private sync: PouchDB.Replication.Sync<{}> | null = null @@ -38,6 +38,7 @@ class CouchService { } constructor() { + this.initDb() if (!this.eventListened) { this.eventListened = true window.addEventListener('online', () => { @@ -50,7 +51,6 @@ class CouchService { }) } } - public async initLive(): Promise { if (!this.db) { return false @@ -230,6 +230,14 @@ class CouchService { this.userSync = null } } + + private initDb(): void { + if (this.user) { + this.db = new PouchDb(`vaquant-${this.user.userId}`) + } else { + this.db = new PouchDb(LOCALE_DB) + } + } } export default new CouchService()