test: fix restore test

isekai-main
Barış Soner Uşaklı 3 years ago
parent e6a46ef6ce
commit 0d9ec9d30e

@ -11,14 +11,12 @@ const batch = require('../batch');
module.exports = function (Topics) {
Topics.delete = async function (tid, uid) {
await Promise.all([
Topics.setTopicFields(tid, {
deleted: 1,
deleterUid: uid,
deletedTimestamp: Date.now(),
}),
removeTopicPidsFromCid(tid),
]);
await removeTopicPidsFromCid(tid);
await Topics.setTopicFields(tid, {
deleted: 1,
deleterUid: uid,
deletedTimestamp: Date.now(),
});
};
async function removeTopicPidsFromCid(tid) {
@ -37,24 +35,20 @@ module.exports = function (Topics) {
]);
let postData = await posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted']);
postData = postData.filter(post => post && !post.deleted);
const pidsToAdd = [];
const scores = [];
postData.forEach((post) => {
pidsToAdd.push(post.pid);
scores.push(post.timestamp);
});
const pidsToAdd = postData.map(post => post.pid);
const scores = postData.map(post => post.timestamp);
await db.sortedSetAdd(`cid:${cid}:pids`, scores, pidsToAdd);
await categories.updateRecentTidForCid(cid);
}
Topics.restore = async function (tid) {
await Topics.deleteTopicFields(tid, [
'deleterUid', 'deletedTimestamp',
]);
await Promise.all([
Topics.setTopicField(tid, 'deleted', 0),
Topics.deleteTopicFields(tid, [
'deleterUid', 'deletedTimestamp',
]),
addTopicPidsToCid(tid),
]);
await Topics.setTopicField(tid, 'deleted', 0);
};
Topics.purgePostsAndTopic = async function (tid, uid) {

Loading…
Cancel
Save