feat: complete MongoDB to CouchDB migration
- Migrate Report model to CouchDB with embedded street/user data - Migrate UserBadge model to CouchDB with badge population - Update all remaining routes (reports, users, badges, payments) to use CouchDB - Add CouchDB health check and graceful shutdown to server.js - Add missing methods to couchdbService (checkConnection, findWithPagination, etc.) - Update Kubernetes deployment manifests for CouchDB support - Add comprehensive CouchDB setup documentation All core functionality now uses CouchDB as primary database while maintaining MongoDB for backward compatibility during transition period. 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -14,7 +14,12 @@ const router = express.Router();
|
||||
router.get(
|
||||
"/",
|
||||
asyncHandler(async (req, res) => {
|
||||
const badges = await Badge.find().sort({ order: 1, rarity: 1 });
|
||||
const badges = await Badge.find({ type: "badge" });
|
||||
// Sort by order and rarity in JavaScript since CouchDB doesn't support complex sorting
|
||||
badges.sort((a, b) => {
|
||||
if (a.order !== b.order) return a.order - b.order;
|
||||
return a.rarity.localeCompare(b.rarity);
|
||||
});
|
||||
res.json(badges);
|
||||
})
|
||||
);
|
||||
@@ -33,7 +38,7 @@ router.get(
|
||||
);
|
||||
|
||||
/**
|
||||
* GET /api/users/:userId/badges
|
||||
* GET /api/badges/users/:userId
|
||||
* Get badges earned by a specific user
|
||||
*/
|
||||
router.get(
|
||||
@@ -41,9 +46,10 @@ router.get(
|
||||
asyncHandler(async (req, res) => {
|
||||
const { userId } = req.params;
|
||||
|
||||
const userBadges = await UserBadge.find({ user: userId })
|
||||
.populate("badge")
|
||||
.sort({ earnedAt: -1 });
|
||||
const userBadges = await UserBadge.findByUser(userId);
|
||||
|
||||
// Sort by earnedAt in JavaScript
|
||||
userBadges.sort((a, b) => new Date(b.earnedAt) - new Date(a.earnedAt));
|
||||
|
||||
res.json(
|
||||
userBadges.map((ub) => ({
|
||||
|
||||
Reference in New Issue
Block a user