-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
54 lines (48 loc) · 1.35 KB
/
api.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
const admin = require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);
var db = admin.firestore();
var users = db.collection('users');
var calls = db.collection('calls');
exports.iotAktif = functions.https.onRequest((req, res) => {
const iotid = req.query.text;
var FieldValue = admin.firestore.FieldValue;
var iotbilgi = users.doc(iotid).get()
.then(doc => {
if (!doc.exists) {
console.log('kullanici yok');
} else {
console.log('bilgiler:', doc.data());
var cagri = db.collection('calls').doc(doc.data().id).set({
id: doc.data().id,
adres: doc.data().adres,
tip: doc.data().tip,
sahip: doc.data().sahip,
update: FieldValue.serverTimestamp(),
konum: doc.data().konum
}).then(ref => {
console.log('Eklendi ', ref.id);
});
}
})
.catch(err => {
console.log('hata', err);
});
res.send("ekleme islemi");
});
exports.iotPasif = functions.https.onRequest((req, res) => {
const iotid = req.query.text;
var iotbilgi = users.doc(iotid).get()
.then(doc => {
if (!doc.exists) {
console.log('kullanici yok');
} else {
console.log('bilgiler:', doc.data());
var deleteDoc = db.collection('calls').doc(iotid).delete();
}
})
.catch(err => {
console.log('hata', err);
});
res.send("silme islemi");
});