Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console.log('🚀 Setting up StackIt Q&A Platform...\n')

// Check if Node.js version is compatible
const nodeVersion = process.version
const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0])
const majorVersion = parseInt(nodeVersion.slice(1, 10).split('.')[0])
if (majorVersion < 16) {
console.error('❌ Node.js version 16 or higher is required')
console.error(`Current version: ${nodeVersion}`)
Expand Down
2 changes: 1 addition & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const shouldEnableRateLimit = () => {
const getRateLimitMax = () => {
// Environment variable override takes precedence
if (process.env.RATE_LIMIT_MAX) {
return parseInt(process.env.RATE_LIMIT_MAX);
return parseInt(process.env.RATE_LIMIT_MAX, 10);
}

// Production: 100 requests per 15 minutes
Expand Down
4 changes: 2 additions & 2 deletions server/routes/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const Notification = require('../models/Notification')
// Get user's notifications
router.get('/', authenticateToken, async (req, res) => {
try {
const page = parseInt(req.query.page) || 1
const limit = parseInt(req.query.limit) || 20
const page = parseInt(req.query.page, 10) || 1
const limit = parseInt(req.query.limit, 10) || 20
const skip = (page - 1) * limit

const notifications = await Notification.find({ recipient: req.user._id })
Expand Down
6 changes: 3 additions & 3 deletions server/routes/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ router.get('/', async (req, res) => {
.populate('author', 'username reputation avatar')
.sort(sortOption)
.skip(skip)
.limit(parseInt(limit))
.limit(parseInt(limit, 10))
.lean()

const total = await Question.countDocuments(query)
const totalPages = Math.ceil(total / limit)

// Add virtual fields
const questionsWithVirtuals = questions.map(q => ({
const questionsWithVirtuals = (questions ?? []).map(q => ({
...q,
voteCount: q.votes.upvotes.length - q.votes.downvotes.length,
totalVotes: q.votes.upvotes.length + q.votes.downvotes.length,
Expand All @@ -126,7 +126,7 @@ router.get('/', async (req, res) => {
res.json({
questions: questionsWithVirtuals,
pagination: {
currentPage: parseInt(page),
currentPage: parseInt(page, 10),
totalPages,
total,
hasNext: page < totalPages,
Expand Down
14 changes: 7 additions & 7 deletions server/routes/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.get('/', async (req, res) => {

const tags = await Tag.find(query)
.sort({ questionCount: -1, name: 1 })
.limit(parseInt(limit))
.limit(parseInt(limit, 10))

res.json(tags)
} catch (error) {
Expand All @@ -34,7 +34,7 @@ router.get('/', async (req, res) => {
router.get('/popular', async (req, res) => {
try {
const { limit = 10 } = req.query
const tags = await Tag.getPopularTags(parseInt(limit))
const tags = await Tag.getPopularTags(parseInt(limit, 10))
res.json(tags)
} catch (error) {
console.error('Error fetching popular tags:', error)
Expand All @@ -46,7 +46,7 @@ router.get('/popular', async (req, res) => {
router.get('/trending', async (req, res) => {
try {
const { limit = 10 } = req.query
const tags = await Tag.getTrendingTags(parseInt(limit))
const tags = await Tag.getTrendingTags(parseInt(limit, 10))
res.json(tags)
} catch (error) {
console.error('Error fetching trending tags:', error)
Expand All @@ -63,7 +63,7 @@ router.get('/search', async (req, res) => {
return res.status(400).json({ message: 'Search query is required' })
}

const tags = await Tag.searchTags(q, parseInt(limit))
const tags = await Tag.searchTags(q, parseInt(limit, 10))
res.json(tags)
} catch (error) {
console.error('Error searching tags:', error)
Expand Down Expand Up @@ -127,16 +127,16 @@ router.get('/:name/questions', async (req, res) => {
.populate('author', 'username')
.sort(sortOption)
.skip(skip)
.limit(parseInt(limit))
.limit(parseInt(limit, 10))

const total = await Question.countDocuments({ tags: tag.name })

res.json({
tag,
questions,
pagination: {
page: parseInt(page),
limit: parseInt(limit),
page: parseInt(page, 10),
limit: parseInt(limit, 10),
total,
pages: Math.ceil(total / limit)
}
Expand Down