fix: only remove deleted tag, closes #11515

isekai-main
Barış Soner Uşaklı 2 years ago
parent 21fb8590e5
commit de2669a2c6

@ -232,10 +232,15 @@ module.exports = function (Topics) {
if (!tids.length) { if (!tids.length) {
return; return;
} }
let topicsTags = await Topics.getTopicsTags(tids);
topicsTags = topicsTags.map(
topicTags => topicTags.filter(topicTag => topicTag && topicTag !== tag)
);
await db.deleteObjectFields( await db.setObjectBulk(
tids.map(tid => `topic:${tid}`), tids.map((tid, index) => ([
['tags'], `topic:${tid}`, { tags: topicsTags[index].join(',') },
]))
); );
}); });
} }

@ -1932,6 +1932,14 @@ describe('Topic\'s', () => {
}); });
}); });
it('should only delete one tag from topic', async () => {
const result1 = await topics.post({ uid: adminUid, tags: ['deleteme1', 'deleteme2', 'deleteme3'], title: 'topic tagged with plugins', content: 'topic 1 content', cid: topic.categoryId });
await topics.deleteTag('deleteme2');
const topicData = await topics.getTopicData(result1.topicData.tid);
const tags = topicData.tags.map(t => t.value);
assert.deepStrictEqual(tags, ['deleteme1', 'deleteme3']);
});
it('should delete tag', (done) => { it('should delete tag', (done) => {
topics.deleteTag('javascript', (err) => { topics.deleteTag('javascript', (err) => {
assert.ifError(err); assert.ifError(err);

Loading…
Cancel
Save