-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (43 loc) · 1.93 KB
/
app.js
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
54
55
56
const express = require('express')
const app = express()
const port = 3001
const firebaseConfig = {
"type": "service_account",
"project_id": "test-query-1e735",
"private_key_id": "----------------------",
"private_key": "-----BEGIN PRIVATE KEY-----\==\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-4c4pb@test-query-1e735.iam.gserviceaccount.com",
"client_id": "_________________",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-4c4pb%40test-query-1e735.iam.gserviceaccount.com"
};
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
const { getFirestore } = require("firebase-admin/firestore");
admin.initializeApp(
{
credential: admin.credential.cert(firebaseConfig),
databaseURL: "https://test-query-1e735-default-rtdb.firebaseio.com"
}
);
const db = getFirestore();
app.get('/', async (req, res) => {
let ref = admin.database().ref(`/TestChatHistory/268/`).limitToLast(2);
ref.orderByChild("timestamp").on("value", function(data) {
data.forEach(function(data) {
console.log("The " + data.key + " rating is " + JSON.stringify(data.val()["timestamp"]));
})
})
// let ref = admin.database().ref(`/TestChatHistory/268/`).limitToFirst(2);
// ref.orderByChild("timestamp").startAfter(1680604052348).on("value", function(data) {
// data.forEach(function(data) {
// console.log("The " + data.key + " rating is " + JSON.stringify(new Date(data.val()["timestamp"])));
// })
// })
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})