-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirestoreManager.js
More file actions
53 lines (44 loc) · 1.13 KB
/
Copy pathFirestoreManager.js
File metadata and controls
53 lines (44 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module.exports = class DbManager{
constructor(){
this.initDb();
}
async initDb(){
const admin = require('firebase-admin');
const serviceAccount = require('./firebasekey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
this.db = admin.firestore();
this.collection = this.db.collection('drugmakerextreme');
}
async getSave(id){
const doc = await this.collection.doc(id).get();
if(!doc.exists) return;
return JSON.stringify(doc.data());
}
async writeSave(id,save){
await this.collection.doc(id).set(JSON.parse(save));
}
}
/*module.exports = class DbManager{
constructor(){
this.initDb();
}
async initDb(){
const admin = require('firebase-admin');
const serviceAccount = require('./firebasekey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
this.db = admin.firestore();
this.document = this.db.collection('drugmakerextreme').doc('users');
}
async getSave(id){
return (await this.document.get()).data()[id];
}
async writeSave(id,save){
const object = {};
object[id] = save;
await this.document.set(object);
}
}*/