🐛 (database) fix init local database
This commit is contained in:
@@ -23,7 +23,7 @@ const LOCALE_DB: string = 'VAQUANT_LOCALE_DB'
|
|||||||
const REMOTE: string = 'https://juliencalixte.ddns.net/database'
|
const REMOTE: string = 'https://juliencalixte.ddns.net/database'
|
||||||
|
|
||||||
class CouchService {
|
class CouchService {
|
||||||
public db: PouchDB.Database | null = new PouchDb(LOCALE_DB)
|
public db: PouchDB.Database | null = null
|
||||||
private innerRemote: PouchDB.Database | null = null
|
private innerRemote: PouchDB.Database | null = null
|
||||||
private user: IUser | null = null
|
private user: IUser | null = null
|
||||||
private sync: PouchDB.Replication.Sync<{}> | null = null
|
private sync: PouchDB.Replication.Sync<{}> | null = null
|
||||||
@@ -38,6 +38,7 @@ class CouchService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.initDb()
|
||||||
if (!this.eventListened) {
|
if (!this.eventListened) {
|
||||||
this.eventListened = true
|
this.eventListened = true
|
||||||
window.addEventListener('online', () => {
|
window.addEventListener('online', () => {
|
||||||
@@ -50,7 +51,6 @@ class CouchService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initLive(): Promise<boolean> {
|
public async initLive(): Promise<boolean> {
|
||||||
if (!this.db) {
|
if (!this.db) {
|
||||||
return false
|
return false
|
||||||
@@ -230,6 +230,14 @@ class CouchService {
|
|||||||
this.userSync = null
|
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()
|
export default new CouchService()
|
||||||
|
|||||||
Reference in New Issue
Block a user