Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Prevent deleting customers with packages #327

Merged
merged 1 commit into from
Dec 3, 2017

Conversation

kenjiO
Copy link
Contributor

@kenjiO kenjiO commented Nov 22, 2017

closes #275

await User.findByIdAndRemove(id)
await Customer.findByIdAndRemove(id)
// Check to see if the customer is associated with any packages
const packages = await Package.find({customer: id})

This comment was marked as off-topic.

@jspaine
Copy link
Contributor

jspaine commented Nov 23, 2017

Looks good, thought you were going for the deleted flag though? But I guess that would only be useful if you wanted to delete the customer and leave the package?

@kenjiO
Copy link
Contributor Author

kenjiO commented Nov 29, 2017

Here it is using count()
I also added a statement to delete the customer from any volunteers it is assigned to.

In the future I still would like to have either a deleted or retired flag for the customer to indicate the customer is no longer with the food bank but to keep its data for record keeping. But for now this prevents packages from referencing a customer that no longer exists.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Packages component breaks if a customer is deleted
2 participants