diff --git a/src/topics/tags.js b/src/topics/tags.js index daab4e5f77..8862d8d4d3 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -17,6 +17,11 @@ const utils = require('../utils'); const batch = require('../batch'); const cache = require('../cache'); +function extractTagValues(tags) { + return tags.map(tagItem => tagItem.value); +} + + module.exports = function (Topics) { Topics.createTags = async function (tags, tid, timestamp) { if (!Array.isArray(tags) || !tags.length) { @@ -158,7 +163,7 @@ module.exports = function (Topics) { // update 'tags' field in topic hash topicData.forEach((topic) => { - topic.tags = topic.tags.map(tagItem => tagItem.value); + topic.tags = extractTagValues(topic.tags); const index = topic.tags.indexOf(tag); if (index !== -1) { topic.tags.splice(index, 1, newTagName);