Skip to content

Commit 8318b07

Browse files
author
puranban
committed
Improve cloud function
1 parent 231ec08 commit 8318b07

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

firebase/functions/src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,15 @@ exports.decProjectProgress = functions.database.ref('/v2/projects/{projectId}/re
346346

347347
exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
348348
try {
349-
const projectRef = admin.database().ref('v2/projects');
350-
const snapshot = projectRef.once('value');
351-
const data = (await snapshot).val();
349+
const projectRef = await admin.database().ref('v2/projects').once('value');
350+
const data = projectRef.val();
352351

353352
if (data) {
354353
const newProjectData: {[key: string]: string} = {};
355354

356355
Object.keys(data).forEach((id) => {
357356
if (data[id]?.projectTopic) {
358-
const newProjectTopicKey = data[id]?.projectTopic?.toLowerCase() as string;
357+
const newProjectTopicKey = data[id].projectTopic?.toLowerCase() as string;
359358
newProjectData[`v2/projects/${id}/projectTopicKey`] = newProjectTopicKey;
360359
}
361360
});
@@ -377,16 +376,15 @@ exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
377376

378377
exports.addUserNameLowercase = functions.https.onRequest(async (_, res) => {
379378
try {
380-
const userRef = admin.database().ref('v2/users');
381-
const snapshot = userRef.once('value');
382-
const data = (await snapshot).val();
379+
const userRef = await admin.database().ref('v2/users').once('value');
380+
const data = userRef.val();
383381

384382
if (data) {
385383
const newUserData: {[key: string]: string} = {};
386384

387385
Object.keys(data).forEach((id) => {
388386
if (data[id]?.username) {
389-
const newUserNameKey = data[id]?.username?.toLowerCase() as string;
387+
const newUserNameKey = data[id].username?.toLowerCase() as string;
390388
newUserData[`v2/users/${id}/userNameKey`] = newUserNameKey;
391389
}
392390
});

0 commit comments

Comments
 (0)