'use strict'; const knex = require('./knex'); async function matchTags(rawTags) { const tagEntries = await knex('tags') .select(knex.raw('ifnull(original.tag, tags.tag) as tag'), knex.raw('ifnull(original.tag, tags.tag) as tag')) .whereIn('tags.tag', rawTags) .orWhereIn('tags.tag', rawTags.map(tag => tag.toLowerCase())) .leftJoin('tags as original', 'tags.alias_for', 'original.tag'); return Array.from(new Set(tagEntries.map(({ tag }) => tag))).sort(); // reduce to tag name and filter duplicates } module.exports = { matchTags };