mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-13 08:13:49 +10:00
Updated "deleteUser" Firebase cloud function to perform updates in an atomic way, tweaked UI call and error handling
This commit is contained in:
@ -19,8 +19,9 @@ const deleteUserFunctionHandler = async (_, { auth }) => {
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Delete user resumes
|
||||
const userId = auth.uid;
|
||||
const updates = {};
|
||||
|
||||
const userResumesDataSnapshot = await admin
|
||||
.database()
|
||||
.ref('resumes')
|
||||
@ -30,18 +31,21 @@ const deleteUserFunctionHandler = async (_, { auth }) => {
|
||||
const userResumes = userResumesDataSnapshot.val();
|
||||
if (userResumes) {
|
||||
Object.keys(userResumes).forEach(async (resumeId) => {
|
||||
await admin.database().ref(`resumes/${resumeId}`).remove();
|
||||
updates[`resumes/${resumeId}`] = null;
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Delete user
|
||||
const userDataSnapshot = await admin
|
||||
.database()
|
||||
.ref(`users/${userId}`)
|
||||
.once('value');
|
||||
const user = userDataSnapshot.val();
|
||||
if (user) {
|
||||
await admin.database().ref(`users/${userId}`).remove();
|
||||
updates[`users/${userId}`] = null;
|
||||
}
|
||||
|
||||
if (Object.keys(updates).length > 0) {
|
||||
await admin.database().ref().update(updates);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user