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-30 03:45:42 +00:00
|
|
|
const tags = rawTags
|
|
|
|
.concat(rawTags.map(tag => tag.toLowerCase()))
|
|
|
|
.concat(rawTags.map(tag => tag.toUpperCase()));
|
|
|
|
|
2019-10-27 23:58:54 +00:00
|
|
|
const tagEntries = await knex('tags')
|
|
|
|
.pluck('aliases.id')
|
2019-10-30 03:45:42 +00:00
|
|
|
.whereIn('tags.name', tags)
|
2019-10-27 23:58:54 +00:00
|
|
|
.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
|
|
|
}
|
|
|
|
|
2019-11-11 02:20:00 +00:00
|
|
|
async function storeTags(release, releaseEntry) {
|
|
|
|
return knex('tags_associated').insert(release.tags.map(tagId => ({
|
|
|
|
tag_id: tagId,
|
|
|
|
release_id: releaseEntry.id,
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
matchTags,
|
|
|
|
storeTags,
|
|
|
|
};
|