Skip to content

Commit

Permalink
only delete household if only parent
Browse files Browse the repository at this point in the history
  • Loading branch information
jho44 committed Oct 1, 2023
1 parent 0a2a6e9 commit bfbfada
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/lib/server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,15 @@ async function deleteUser(user: User) {
});
}

// delete their household
if (user.householdId) await deleteHousehold(user);
// delete their household if they're the last member of their household
if (user.householdId) {
const householdUsers = await prisma.user.findMany({
where: {
householdId: user.householdId
}
});
if (householdUsers.length === 1) await deleteHousehold(user);
}

// delete the user
await prisma.user.delete({
Expand Down
2 changes: 1 addition & 1 deletion src/routes/household/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
case ModalReason.DELETE_ACCOUNT:
modalText.heading = 'Delete Account';
modalText.content =
"Are you sure that you'd like to delete your account? This will delete all basic household info and associated children but leave all adult users' accounts intact. Additionally, we'll delete your profile info, but keep track of your phone permission settings.";
"Are you sure that you'd like to delete your account? If you are the last adult in your household, this will delete all basic household info and associated children. Otherwise, the household's info and other adult users' accounts will remain intact. Additionally, we'll delete your profile info, but keep track of your phone permission settings.";
break;
default:
throw new Error(`Undefined modal reason type ${type}`);
Expand Down

0 comments on commit bfbfada

Please sign in to comment.