-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62b2faa
commit 413f87b
Showing
8 changed files
with
88 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { bonusStars } from '../collections.js'; | ||
|
||
/** | ||
* Get the ids of a user's starred bonuses. | ||
* @param {ObjectId} userId - The user ID | ||
* @returns {Promise<ObjectId[]>} The bonus IDs | ||
*/ | ||
export default async function getBonusIds (userId) { | ||
const aggregation = [ | ||
{ $match: { user_id: userId } }, | ||
{ $addFields: { insertTime: { $toDate: '$_id' } } }, | ||
{ $sort: { insertTime: -1 } } | ||
]; | ||
|
||
const bonusIds = await bonusStars.aggregate(aggregation).toArray(); | ||
return bonusIds.map(bonus => bonus.bonus_id); | ||
} |
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,17 @@ | ||
import { tossupStars } from '../collections.js'; | ||
|
||
/** | ||
* Get the ids of a user's starred tossups. | ||
* @param {ObjectId} userId - The user ID | ||
* @returns {Promise<ObjectId[]>} The tossup IDs | ||
*/ | ||
export default async function getTossupIds (userId) { | ||
const aggregation = [ | ||
{ $match: { user_id: userId } }, | ||
{ $addFields: { insertTime: { $toDate: '$_id' } } }, | ||
{ $sort: { insertTime: -1 } } | ||
]; | ||
|
||
const tossupIds = await tossupStars.aggregate(aggregation).toArray(); | ||
return tossupIds.map(tossup => tossup.tossup_id); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import getUserId from '../../../database/account-info/get-user-id.js'; | ||
import getBonusIds from '../../../database/account-info/stars/get-ids-bonus.js'; | ||
|
||
import { Router } from 'express'; | ||
|
||
const router = Router(); | ||
|
||
router.get('/', async (req, res) => { | ||
const username = req.session.username; | ||
const userId = await getUserId(username); | ||
const ids = await getBonusIds(userId); | ||
res.json(ids); | ||
}); | ||
|
||
export default router; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import getUserId from '../../../database/account-info/get-user-id.js'; | ||
import getTossupIds from '../../../database/account-info/stars/get-ids-tossup.js'; | ||
|
||
import { Router } from 'express'; | ||
|
||
const router = Router(); | ||
|
||
router.get('/', async (req, res) => { | ||
const username = req.session.username; | ||
const userId = await getUserId(username); | ||
const ids = await getTossupIds(userId); | ||
res.json(ids); | ||
}); | ||
|
||
export default router; |