-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding routes and migration script for bookmarking (#126)
* Adding routes and migration script for bookmarking * Refactoring WeeklyDebrief * Fixing unbookmarking functions * Adding (un)bookmark articles tests * More article bookmark tests * Adding more tests for flyers and magazines
- Loading branch information
1 parent
b70e2f1
commit 8acc8fa
Showing
9 changed files
with
281 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = { | ||
async up(db) { | ||
/** | ||
* Adds the bookmarkedArticles, bookmarkedMagazines, and bookmarkedFlyers fields to all users. | ||
* Removes the numBookmarkedArticles field from all users | ||
*/ | ||
const users = await db.collection('users').find({}).toArray(); | ||
users.map(async (user) => { | ||
await db | ||
.collection('users') | ||
.updateOne( | ||
{ _id: user._id }, | ||
{ $set: { bookmarkedArticles: [], bookmarkedMagazines: [], bookmarkedFlyers: [] } }, | ||
); | ||
await db | ||
.collection('users') | ||
.updateOne({ _id: user._id }, { $unset: { numBookmarkedArticles: '' } }); | ||
return user; | ||
}); | ||
}, | ||
|
||
async down(db) { | ||
/** | ||
* Removes the bookmarkedArticles, bookmarkedMagazines, and bookmarkedFlyers fields from all users. | ||
* Adds the numBookmarkedArticles field to all users | ||
*/ | ||
const users = await db.collection('users').find({}).toArray(); | ||
users.map(async (user) => { | ||
await db | ||
.collection('users') | ||
.updateOne( | ||
{ _id: user._id }, | ||
{ $unset: { bookmarkedArticles: '', bookmarkedMagazines: '', bookmarkedFlyers: '' } }, | ||
); | ||
await db | ||
.collection('users') | ||
.updateOne({ _id: user._id }, { $set: { numBookmarkedArticles: 0 } }); | ||
return user; | ||
}); | ||
}, | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.