Skip to content

Commit

Permalink
Migrate last remaining mongodb import to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
J12934 committed Jan 13, 2024
1 parent 6ef153a commit 11a9c1b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions routes/likeProductReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
import challengeUtils = require('../lib/challengeUtils')
import { type Request, type Response, type NextFunction } from 'express'
import { type Review } from '../data/types'
import * as db from '../data/mongodb'

const challenges = require('../data/datacache').challenges
const db = require('../data/mongodb')
const security = require('../lib/insecurity')

module.exports = function productReviews () {
return (req: Request, res: Response, next: NextFunction) => {
const id = req.body.id
const user = security.authenticatedUsers.from(req)
db.reviews.findOne({ _id: id }).then((review: Review) => {
db.reviewsCollection.findOne({ _id: id }).then((review: Review) => {
if (!review) {
res.status(404).json({ error: 'Not found' })
} else {
const likedBy = review.likedBy
if (!likedBy.includes(user.data.email)) {
db.reviews.update(
db.reviewsCollection.update(
{ _id: id },
{ $inc: { likesCount: 1 } }
).then(
() => {
// Artificial wait for timing attack challenge
setTimeout(function () {
db.reviews.findOne({ _id: id }).then((review: Review) => {
db.reviewsCollection.findOne({ _id: id }).then((review: Review) => {
const likedBy = review.likedBy
likedBy.push(user.data.email)
let count = 0
Expand All @@ -38,7 +38,7 @@ module.exports = function productReviews () {
}
}
challengeUtils.solveIf(challenges.timingAttackChallenge, () => { return count > 2 })
db.reviews.update(
db.reviewsCollection.update(
{ _id: id },
{ $set: { likedBy } }
).then(
Expand Down

0 comments on commit 11a9c1b

Please sign in to comment.