|
|
@ -92,13 +92,13 @@ module Firebase { |
|
|
|
|
|
|
|
|
class FirebaseIntegration implements IntegrationBase { |
|
|
class FirebaseIntegration implements IntegrationBase { |
|
|
private config: FirebaseConfig |
|
|
private config: FirebaseConfig |
|
|
private db: Firestore |
|
|
private client: Firestore |
|
|
|
|
|
|
|
|
constructor(config: FirebaseConfig) { |
|
|
constructor(config: FirebaseConfig) { |
|
|
this.config = config |
|
|
this.config = config |
|
|
if (config.serviceAccount) { |
|
|
if (config.serviceAccount) { |
|
|
const serviceAccount = JSON.parse(config.serviceAccount) |
|
|
const serviceAccount = JSON.parse(config.serviceAccount) |
|
|
this.db = new Firestore({ |
|
|
this.client = new Firestore({ |
|
|
projectId: serviceAccount.project_id, |
|
|
projectId: serviceAccount.project_id, |
|
|
credentials: { |
|
|
credentials: { |
|
|
client_email: serviceAccount.client_email, |
|
|
client_email: serviceAccount.client_email, |
|
|
@ -106,7 +106,7 @@ module Firebase { |
|
|
}, |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
this.db = new Firestore({ |
|
|
this.client = new Firestore({ |
|
|
projectId: config.projectId, |
|
|
projectId: config.projectId, |
|
|
credentials: { |
|
|
credentials: { |
|
|
client_email: config.email, |
|
|
client_email: config.email, |
|
|
@ -118,7 +118,7 @@ module Firebase { |
|
|
|
|
|
|
|
|
async create(query: { json: object; extra: { [key: string]: string } }) { |
|
|
async create(query: { json: object; extra: { [key: string]: string } }) { |
|
|
try { |
|
|
try { |
|
|
const documentReference = this.db |
|
|
const documentReference = this.client |
|
|
.collection(query.extra.collection) |
|
|
.collection(query.extra.collection) |
|
|
.doc() |
|
|
.doc() |
|
|
await documentReference.set({ ...query.json, id: documentReference.id }) |
|
|
await documentReference.set({ ...query.json, id: documentReference.id }) |
|
|
@ -133,7 +133,7 @@ module Firebase { |
|
|
async read(query: { json: object; extra: { [key: string]: string } }) { |
|
|
async read(query: { json: object; extra: { [key: string]: string } }) { |
|
|
try { |
|
|
try { |
|
|
let snapshot |
|
|
let snapshot |
|
|
const collectionRef = this.db.collection(query.extra.collection) |
|
|
const collectionRef = this.client.collection(query.extra.collection) |
|
|
if ( |
|
|
if ( |
|
|
query.extra.filterField && |
|
|
query.extra.filterField && |
|
|
query.extra.filter && |
|
|
query.extra.filter && |
|
|
@ -164,19 +164,19 @@ module Firebase { |
|
|
extra: { [key: string]: string } |
|
|
extra: { [key: string]: string } |
|
|
}) { |
|
|
}) { |
|
|
try { |
|
|
try { |
|
|
await this.db |
|
|
await this.client |
|
|
.collection(query.extra.collection) |
|
|
.collection(query.extra.collection) |
|
|
.doc(query.json.id) |
|
|
.doc(query.json.id) |
|
|
.update(query.json) |
|
|
.update(query.json) |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
await this.db |
|
|
await this.client |
|
|
.collection(query.extra.collection) |
|
|
.collection(query.extra.collection) |
|
|
.doc(query.json.id) |
|
|
.doc(query.json.id) |
|
|
.get() |
|
|
.get() |
|
|
).data() |
|
|
).data() |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
console.error("Error writing to firebase", err) |
|
|
console.error("Error writing to Firestore", err) |
|
|
throw err |
|
|
throw err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -186,13 +186,13 @@ module Firebase { |
|
|
extra: { [key: string]: string } |
|
|
extra: { [key: string]: string } |
|
|
}) { |
|
|
}) { |
|
|
try { |
|
|
try { |
|
|
await this.db |
|
|
await this.client |
|
|
.collection(query.extra.collection) |
|
|
.collection(query.extra.collection) |
|
|
.doc(query.json.id) |
|
|
.doc(query.json.id) |
|
|
.delete() |
|
|
.delete() |
|
|
return true |
|
|
return true |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
console.error("Error writing to mongodb", err) |
|
|
console.error("Error deleting from Firestore", err) |
|
|
throw err |
|
|
throw err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|