Skip to content

Commit

Permalink
Added feature to query quotes using anime name
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrea committed May 20, 2024
1 parent dbd18cf commit 6e4a36c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/controllers/v4/textUtilities/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ const getQuote = async (req, res, next) => {
* Extract character parameter from the query
* @type {string}
*/
const { character } = req.query;
const { character, anime } = req.query;

/**
* Create a filter object based on the optional character parameter
* @type {Object}
*/
const filter = character ? { author: character } : {};

/**
* Create a filter object based on the optional character and anime parameters
* @type {Object}
*/
const filter = {};
if (character) {
filter.author = { $regex: character, $options: 'i' };
}
if (anime) {
filter.anime = { $regex: anime, $options: 'i' };
}
/**
* Aggregate to match the filter, select a random quote, and project excluding version field
* @type {Array<Object>}
Expand Down

0 comments on commit 6e4a36c

Please sign in to comment.