2019-03-24 00:29:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-03-25 02:57:33 +00:00
|
|
|
const knex = require('./knex');
|
|
|
|
|
|
|
|
async function matchTags(rawTags) {
|
2019-10-27 23:58:54 +00:00
|
|
|
const tagEntries = await knex('tags')
|
|
|
|
.pluck('aliases.id')
|
|
|
|
.whereIn('tags.name', rawTags.map(tag => tag.toLowerCase()))
|
|
|
|
.where(function where() {
|
|
|
|
this
|
|
|
|
.whereNull('tags.alias_for')
|
|
|
|
.orWhereNull('aliases.alias_for');
|
|
|
|
})
|
|
|
|
.join('tags as aliases', function join() {
|
|
|
|
this
|
|
|
|
.on('tags.alias_for', 'aliases.id')
|
|
|
|
.orOn('tags.id', 'aliases.id');
|
|
|
|
})
|
|
|
|
.groupBy('aliases.id');
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2019-10-27 23:58:54 +00:00
|
|
|
return tagEntries;
|
2019-03-25 02:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { matchTags };
|