Skip to content

Admin audit 2026 06 03#1

Merged
David-Antony merged 6 commits into
masterfrom
admin-audit-2026-06-03
Jun 3, 2026
Merged

Admin audit 2026 06 03#1
David-Antony merged 6 commits into
masterfrom
admin-audit-2026-06-03

Conversation

@David-Antony

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 3, 2026 13:32
@David-Antony David-Antony merged commit 8a37dd4 into master Jun 3, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds admin-facing tooling to audit MongoDB indexes and to recompute likeCount fields from likedBy, and tightens the API to prevent likeCount from being set directly via design-item updates.

Changes:

  • Added admin API endpoints for recomputing like counts, auditing indexes, and viewing recent admin audit records.
  • Added a lightweight static admin page + JS to invoke the new admin endpoints.
  • Added Node.js tooling scripts for audit/recompute and updated jsdom dependency version.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
tools/adminForceRecompute.js Adds a CLI recompute script using an aggregation-pipeline updateMany.
tools/adminAudit.js Adds a CLI audit script that recomputes like counts and prints index info.
server.js Prevents design-item likeCount writes via CRUD updates; adds admin endpoints for recompute/audit/history.
public/admin.js Adds a small browser script to call the new admin endpoints with a JWT.
public/admin.html Adds a static admin UI page for audit/recompute/history operations.
package.json Adds admin-audit script and changes jsdom version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$expr: {
$ne: [
{ $ifNull: ["$likeCount", null] },
{ $size: { $ifNull: ["$likedBy", []] } }
Comment on lines +24 to +25
likedBy: { $ifNull: ["$likedBy", []] },
likeCount: { $size: { $ifNull: ["$likedBy", []] } }
Comment thread tools/adminAudit.js
const summary = {};
for (const name of collectionNames) {
const col = db.collection(name);
const cursor = col.find();
Comment thread tools/adminAudit.js

if (matched > 0) {
const result = await bulk.execute();
modified = result.nModified || result.nModified === undefined ? (result.nModified || Object.values(result).reduce((s, v) => s + (v.nModified || 0), 0)) : result.nModified;
Comment thread tools/adminAudit.js
const db = client.db(DB_NAME);
console.log('Connected to', uri, 'db:', DB_NAME);

const targets = ['posts', 'designItems', 'staticBlogItems', 'achievers'];
Comment thread server.js
Comment on lines +549 to +553
buildUpdate: (body) => ({
title: body.title,
imageUrl: body.imageUrl,
category: body.category
}),
Comment thread public/admin.html
<h2>Admin: Audit & Recompute</h2>
<p>Paste an admin JWT below, then run the audit or recompute operations.</p>
<div class="row">
<input id="token" type="text" placeholder="Bearer token" />
Comment thread public/admin.html
</div>

<h3>Result</h3>
<textarea id="output" readonly></textarea>
Comment thread package.json
"express-rate-limit": "^8.5.2",
"helmet": "^8.2.0",
"jsdom": "^29.1.1",
"jsdom": "^22.1.0",
const db = client.db(DB_NAME);
console.log('Connected to', uri, 'db:', DB_NAME);

const targets = ['posts', 'designItems', 'staticBlogItems', 'achievers'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants