router.post('/stripe/fetch-checkout-session', async (req, res) => { try { const { bookId, redirectUrl } = req.body; const book = await Book.findById(bookId).select(['slug']).setOptions({ lean: true }); if (!book) { throw new Error('Book not found'); } const isPurchased = (await Purchase.find({ userId: req.user._id, bookId: book._id }).countDocuments()) > 0; if (isPurchased) { throw new Error('Already bought this book'); } const session = await createSession({ userId: req.user._id.toString(), userEmail: req.user.email, bookId, bookSlug: book.slug, redirectUrl, }); res.json({ sessionId: session.id }); } catch (err) { logger.error(err); res.json({ error: err.message || err.toString() }); } });
const gzip = zlib.createGzip(); const chapters = Chapter.find({}, 'slug').sort({ order: 1 }).setOptions({ lean: true });
/* GET home page. */ router.get('/arrivals', function(req, res){ //retrieves the arrival flight info from mongodb FlightSchema.find() .setOptions({sort:'arrivedAt'}) .exec(function(err, arrivals){ if(err){ console.log(err); res.status(500).json({'status':'failure'}); } else { res.locals.title = 'All arrivals'; res.locals.arrivals = arrivals; res.locals.lastNumber = req.session.lastNumber; res.render('arrivals'); } }); });
router.post('/stripe/fetch-checkout-session', async (req, res) => { try { const { bookId, redirectUrl } = req.body; const book = await Book.findById(bookId).select(['slug']).setOptions({ lean: true }); if (!book) { throw new Error('Book not found'); } const isPurchased = (await Purchase.find({ userId: req.user._id, bookId: book._id }).countDocuments()) > 0; if (isPurchased) { throw new Error('Already bought this book'); } const session = await createSession({ userId: req.user._id.toString(), userEmail: req.user.email, bookId, bookSlug: book.slug, redirectUrl, }); res.json({ sessionId: session.id }); } catch (err) { logger.error(err); res.json({ error: err.message || err.toString() }); } });
const gzip = zlib.createGzip(); const chapters = Chapter.find({}, 'slug').sort({ order: 1 }).setOptions({ lean: true });