nkowaokwu / igbo_api

An API exposing Igbo words, definitions, and more
https://igboapi.com
Apache License 2.0
315 stars 138 forks source link

Perform a check within pre-find Mongoose Middleware #181

Closed ijemmao closed 3 years ago

ijemmao commented 3 years ago

Background

There's a number of locations in the controller files that perform a "related collection check" to see if an associated WordSuggestion, ExampleSuggestion, or GenericWord already exist before attempting to create a new Word or Example document.

The Problem

These checks should happen with a Mongoose pre-find middleware so that logic doesn't muddy up the words.js and examples.js controllers files. The related WordSuggestion, ExampleSuggestion, and GenericWord ids are later used to update their merge properties with the following utils function: https://github.com/ijemmao/igbo_api/blob/master/src/controllers/utils/index.js#L95-L99

Words pre-find check

https://github.com/ijemmao/igbo_api/blob/master/src/controllers/words.js#L149-L157

Examples pre-find check

https://github.com/ijemmao/igbo_api/blob/master/src/controllers/examples.js#L67-L74

ijemmao commented 3 years ago

Closing this ticket since it's outdated.