This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
74 lines (64 loc) · 1.42 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
const Firestore = require("@google-cloud/firestore");
const firestore = new Firestore();
const collection = firestore.collection("posts");
exports.create = (request, response) => {
const body = request.body;
collection
.doc(`${body.title}`)
.set({
title: body.title,
text: body.text
})
.then(() => {
response.sendStatus(200);
})
.catch(() => {
console.warn("Error creating!");
response.sendStatus(400);
});
};
exports.read = (request, response) => {
collection
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
})
.then(() => {
response.sendStatus(200);
})
.catch(() => {
console.warn("Error reading!");
response.sendStatus(400);
});
};
exports.update = (request, response) => {
const body = request.body;
collection
.doc(`${body.title}`)
.set({
text: body.text
})
.then(() => {
response.sendStatus(200);
})
.catch(() => {
console.warn("Error updating!");
response.sendStatus(400);
});
};
exports.delete = (request, response) => {
const body = request.body;
collection
.doc(`${body.title}`)
.delete()
.then(() => {
response.sendStatus(200);
})
.catch(() => {
console.warn("Error deleting!");
response.sendStatus(400);
});
};