Skip to content
Merged
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
78 changes: 64 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"mongodb": "^4.13.0",
"mongoose": "^6.6.5",
"nanoid": "^3.3.4",
"node": "^25.1.0",
"passport": "^0.6.0",
"passport-saml": "^3.2.4",
"qrcode.react": "^4.0.1"
Expand Down
53 changes: 53 additions & 0 deletions src/routes/checkpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import express from 'express';
import User from '../models/user';
import isAuthenticated from '../middlewares/isAuthenticated';

export const checkpointsRoute = express.Router();

checkpointsRoute.post('/redeem', async (req, res) => {
try {
const { userId } = req.body;

const user = await User.findByIdAndUpdate(
userId,
{
$inc: { n_checkpoints: 1 },
$push: { timestamps: new Date() }
},
{ new: true }
);

if (!user) {
return res.status(404).json({ error: 'User not found' });
}

res.json({
success: true,
n_checkpoints: user.n_checkpoints,
timestamps: user.timestamps
});
} catch (error) {
console.error('Error redeeming checkpoint:', error);
res.status(500).json({ error: 'Failed to redeem checkpoint' });
}
});

checkpointsRoute.get('/:userId', isAuthenticated, async (req, res) => {
try {
const { userId } = req.params;

const user = await User.findById(userId).select('n_checkpoints timestamps');

if (!user) {
return res.status(404).json({ error: 'User not found' });
}

res.json({
n_checkpoints: user.n_checkpoints,
timestamps: user.timestamps
});
} catch (error) {
console.error('Error fetching checkpoints:', error);
res.status(500).json({ error: 'Failed to fetch checkpoints' });
}
});
2 changes: 2 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { authRoute } from './auth';
import { eventsRoute } from './events';
import { profileRoute } from './profile';
import { usersRoute } from './users';
import { checkpointsRoute } from './checkpoints';

export const routes = express.Router();

routes.use('/auth', authRoute);
routes.use('/events', eventsRoute);
routes.use('/profile', isAuthenticated, profileRoute);
routes.use('/users', isAuthenticated, usersRoute);
routes.use('/checkpoints', checkpointsRoute);

routes.use((_req, res) => {
res.sendStatus(404);
Expand Down
Loading