delete all owned studies

scrub-username
Thibault Duplessis 2021-04-13 13:29:53 +02:00
parent 1d515dedaf
commit 5fdd41efda
1 changed files with 3 additions and 8 deletions

View File

@ -183,23 +183,18 @@ deleteAll('storm_day', '_id', new RegExp(`^${userId}:`));
deleteAll('streamer', '_id');
replaceWithNewGhostIds('study', 'ownerId', studyDb);
const studyIds = scrub(
'study',
studyDb
)(c => {
const ids = c.distinct('_id', { ownerId: userId });
c.remove({ ownerId: userId });
c.updateMany({ likers: userId }, { $pull: { likers: userId } });
const ids = c.distinct('_id', { uids: userId });
c.updateMany({ uids: userId }, { $pull: { uids: userId }, $unset: { [`members.${userId}`]: true } });
return ids;
});
scrub(
'study_chapter_flat',
studyDb
)(c =>
c.find({ _id: { $in: studyIds }, ownerId: userId }, { _id: 1 }).forEach(doc => setNewGhostId(c, doc, 'ownerId'))
);
scrub('study_chapter_flat', studyDb)(c => c.remove({ studyId: { $in: studyIds } }));
deleteAllIn(studyDb, 'study_user_topic', '_id');