Skip to content

Commit e8b47a0

Browse files
committed
Feat: Add initial functionality
1 parent 936f085 commit e8b47a0

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

index.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict'
2+
3+
const admin = require('firebase-admin')
4+
5+
module.exports = class FirestoreDBContextStore {
6+
constructor(serviceAccount, collectionName) {
7+
if (!serviceAccount) {
8+
throw new Error('Need a valid serviceAccount.json')
9+
}
10+
11+
this.serviceAccount = serviceAccount
12+
this.collectionName = collectionName || 'installedApps'
13+
14+
admin.initializeApp({
15+
credential: admin.credential.cert(this.serviceAccount)
16+
})
17+
this.db = admin.firestore()
18+
this.installedApps = this.db.collection(this.collectionName)
19+
}
20+
21+
get(installedAppId) {
22+
return new Promise((resolve, reject) => {
23+
this.installedApps
24+
.doc(installedAppId)
25+
.get()
26+
.then(snapshot => {
27+
resolve(snapshot.data())
28+
})
29+
.catch(reject)
30+
})
31+
}
32+
33+
put(params) {
34+
return new Promise((resolve, reject) => {
35+
this.installedApps
36+
.doc(params.installedAppId)
37+
.set(params, {merge: true})
38+
.then(resolve)
39+
.catch(reject)
40+
})
41+
}
42+
43+
update(installedAppId, params) {
44+
return new Promise((resolve, reject) => {
45+
this.installedApps
46+
.doc(installedAppId)
47+
.update(params, {merge: true})
48+
.then(resolve)
49+
.catch(reject)
50+
})
51+
}
52+
53+
delete(installedAppId) {
54+
return new Promise((resolve, reject) => {
55+
this.installedApps
56+
.doc(installedAppId)
57+
.delete()
58+
.then(resolve)
59+
.catch(reject)
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)