Skip to content

Commit 716d82e

Browse files
authored
Merge pull request #931 from mapswipe/feature/unique-project-title
Add validation for unique project while creating
2 parents e9c49f6 + deb41d9 commit 716d82e

File tree

4 files changed

+1561
-998
lines changed

4 files changed

+1561
-998
lines changed

firebase/functions/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"axios": "^0.25.0",
1818
"cookie-parser": "^1.4.4",
1919
"firebase-admin": "^10.0.2",
20-
"firebase-functions": "^3.18.0",
20+
"firebase-functions": "^3.24.1",
2121
"request": "^2.88.2",
2222
"request-promise-native": "^1.0.8",
2323
"simple-oauth2": "3.3.0"
@@ -35,7 +35,7 @@
3535
"typescript": "^4.5.4"
3636
},
3737
"engines": {
38-
"node": "16"
38+
"node": "18"
3939
},
4040
"private": true
4141
}

firebase/functions/src/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,34 @@ exports.incProjectProgress = functions.database.ref('/v2/projects/{projectId}/re
343343
exports.decProjectProgress = functions.database.ref('/v2/projects/{projectId}/requiredResults/').onUpdate(() => {
344344
return null;
345345
});
346+
347+
exports.addProjectTopicKey = functions.https.onRequest(async (_, res) => {
348+
try {
349+
const projectRef = admin.database().ref('v2/projects');
350+
const snapshot = projectRef.once('value');
351+
const data = (await snapshot).val();
352+
353+
if (data) {
354+
const newProjectData: {[key: string]: string} = {};
355+
356+
Object.keys(data).forEach((id) => {
357+
if (data[id]?.projectTopic) {
358+
const newProjectTopicKey = data[id]?.projectTopic?.toLowerCase() as string;
359+
newProjectData[`v2/projects/${id}/projectTopicKey`] = newProjectTopicKey;
360+
}
361+
});
362+
// NOTE: Update database with the new topic key
363+
await admin.database().ref().update(newProjectData);
364+
365+
// Fetch updated data
366+
const updatedSnapshot = await admin.database().ref('v2/projects').once('value');
367+
const updatedProjectData = updatedSnapshot.val();
368+
369+
res.status(200).send(updatedProjectData);
370+
} else {
371+
res.status(404).send('No projects found');
372+
}
373+
} catch (error) {
374+
res.status(500).send('Error fetching projects data');
375+
}
376+
});

0 commit comments

Comments
 (0)