Adding UI of FeedBack, Registration, Admin console

This commit is contained in:
2026-05-12 20:54:15 +07:00
parent 6a48d6351c
commit dd95ff5a21
30 changed files with 10038 additions and 36 deletions
+89
View File
@@ -0,0 +1,89 @@
/**
* Idempotent seed: upserts rows from app/data/admin.json, then optional legacy data/user-submissions.json.
* Run: npm run db:seed
* Requires MONGODB_URI in .env or .env.local
*/
import { config } from "dotenv";
import { existsSync, readFileSync } from "fs";
import path from "path";
config({ path: path.join(process.cwd(), ".env.local") });
config({ path: path.join(process.cwd(), ".env") });
import connectDB from "../lib/mongodb";
import SummitRequest from "../models/SummitRequest";
import type { AdminRequestRow } from "../types/admin-submission";
type AdminJson = { requests: AdminRequestRow[] };
function loadJsonRequests(): AdminRequestRow[] {
const adminPath = path.join(process.cwd(), "app", "data", "admin.json");
const raw = JSON.parse(readFileSync(adminPath, "utf-8")) as AdminJson;
return raw.requests ?? [];
}
function loadLegacyFileRequests(): AdminRequestRow[] {
const p = path.join(process.cwd(), "data", "user-submissions.json");
if (!existsSync(p)) return [];
try {
const raw = JSON.parse(readFileSync(p, "utf-8")) as unknown;
return Array.isArray(raw) ? (raw as AdminRequestRow[]) : [];
} catch {
return [];
}
}
function rowToInsert(row: AdminRequestRow) {
return {
publicId: row.id,
submittedAt: row.submittedAt,
displayDate: row.displayDate,
fullName: row.fullName,
jobTitle: row.jobTitle ?? "",
company: row.company ?? "",
segment: row.segment,
email: row.email ?? "",
phone: row.phone ?? "",
status: row.status,
notes: row.notes ?? "",
source: row.source,
};
}
async function upsertRow(row: AdminRequestRow) {
return SummitRequest.updateOne(
{ publicId: row.id },
{ $setOnInsert: rowToInsert(row) },
{ upsert: true },
);
}
async function main() {
await connectDB();
let inserted = 0;
let skipped = 0;
const fromAdmin = loadJsonRequests();
for (const row of fromAdmin) {
const res = await upsertRow(row);
if (res.upsertedCount) inserted++;
else skipped++;
}
const fromLegacy = loadLegacyFileRequests();
for (const row of fromLegacy) {
const res = await upsertRow(row);
if (res.upsertedCount) inserted++;
else skipped++;
}
console.log(
`Seed finished. admin.json: ${fromAdmin.length} rows, legacy file: ${fromLegacy.length} rows. New documents: ${inserted}, already existed: ${skipped}.`,
);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});