mongoose middleware to automate the saving of categories based on a terminal category