Skip to content

Commit 727ad07

Browse files
committed
make Firestore sample pass linter
1 parent 0e5ad21 commit 727ad07

File tree

1 file changed

+30
-26
lines changed
  • 2nd-gen/uppercase-firestore/functions

1 file changed

+30
-26
lines changed

2nd-gen/uppercase-firestore/functions/index.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
'use strict';
16+
"use strict";
1717

1818
// [START all]
1919
// [START import]
20-
// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
21-
const {logger} = require('firebase-functions');
22-
const {onRequest} = require('firebase-functions/v2/https');
23-
const {onDocumentCreated} = require('firebase-functions/v2/firestore');
20+
// The Cloud Functions for Firebase SDK to create Cloud Functions and triggers.
21+
const {logger} = require("firebase-functions");
22+
const {onRequest} = require("firebase-functions/v2/https");
23+
const {onDocumentCreated} = require("firebase-functions/v2/firestore");
2424

2525
// The Firebase Admin SDK to access Firestore.
2626
const {initializeApp} = require("firebase-admin/app");
@@ -30,42 +30,46 @@ initializeApp();
3030
// [END import]
3131

3232
// [START addmessage]
33-
// Take the text parameter passed to this HTTP endpoint and insert it into
33+
// Take the text parameter passed to this HTTP endpoint and insert it into
3434
// Firestore under the path /messages/:documentId/original
3535
// [START addmessageTrigger]
3636
exports.addmessage = onRequest(async (req, res) => {
37-
// [END addmessageTrigger]
37+
// [END addmessageTrigger]
3838
// Grab the text parameter.
3939
const original = req.query.text;
4040
// [START adminSdkAdd]
4141
// Push the new message into Firestore using the Firebase Admin SDK.
42-
const writeResult = await getFirestore().collection('messages').add({original: original});
42+
const writeResult = await getFirestore()
43+
.collection("messages")
44+
.add({original: original});
4345
// Send back a message that we've successfully written the message
4446
res.json({result: `Message with ID: ${writeResult.id} added.`});
4547
// [END adminSdkAdd]
4648
});
4749
// [END addmessage]
4850

4951
// [START makeuppercase]
50-
// Listens for new messages added to /messages/:documentId/original and creates an
51-
// uppercase version of the message to /messages/:documentId/uppercase
52+
// Listens for new messages added to /messages/:documentId/original
53+
// and saves an uppercased version of the message
54+
// to /messages/:documentId/uppercase
5255
// [START makeuppercaseTrigger]
53-
exports.makeuppercase = onDocumentCreated('/messages/{documentId}', (event) => {
54-
// [END makeuppercaseTrigger]
55-
// [START makeUppercaseBody]
56-
// Grab the current value of what was written to Firestore.
57-
const original = event.data.data().original;
56+
exports.makeuppercase = onDocumentCreated("/messages/{documentId}", (event) => {
57+
// [END makeuppercaseTrigger]
58+
// [START makeUppercaseBody]
59+
// Grab the current value of what was written to Firestore.
60+
const original = event.data.data().original;
5861

59-
// Access the parameter `{documentId}` with `context.params`
60-
logger.log('Uppercasing', context.params.documentId, original);
61-
62-
const uppercase = original.toUpperCase();
63-
64-
// You must return a Promise when performing asynchronous tasks inside a Functions such as
65-
// writing to Firestore.
66-
// Setting an 'uppercase' field in Firestore document returns a Promise.
67-
return event.data.ref.set({uppercase}, {merge: true});
68-
// [END makeUppercaseBody]
69-
});
62+
// Access the parameter `{documentId}` with `event.params`
63+
logger.log("Uppercasing", event.params.documentId, original);
64+
65+
const uppercase = original.toUpperCase();
66+
67+
// You must return a Promise when performing
68+
// asynchronous tasks inside a function
69+
// such as writing to Firestore.
70+
// Setting an 'uppercase' field in Firestore document returns a Promise.
71+
return event.data.ref.set({uppercase}, {merge: true});
72+
// [END makeUppercaseBody]
73+
});
7074
// [END makeuppercase]
7175
// [END all]

0 commit comments

Comments
 (0)