feat(about): sync FE-BE data and image upload

This commit is contained in:
2026-02-06 01:58:56 +07:00
parent fb8676879d
commit 8232a36e71
16 changed files with 1096 additions and 2821 deletions

48
scripts/migrateAboutUs.js Normal file
View File

@@ -0,0 +1,48 @@
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const fs = require("fs");
const path = require("path");
// Load environment variables
dotenv.config();
const AboutUs = require("../models/aboutUs");
const migrate = async () => {
try {
console.log("🚀 Starting About Us migration...");
// 1. Connect to MongoDB
await mongoose.connect(process.env.MONGODB_URI);
console.log("✅ MongoDB Connected");
// 2. Read about.json from Backend (Source of Truth)
const jsonPath = path.join(__dirname, "../data/about.json");
if (!fs.existsSync(jsonPath)) {
throw new Error(`Source about.json not found at: ${jsonPath}`);
}
const rawData = fs.readFileSync(jsonPath, "utf8");
const jsonData = JSON.parse(rawData);
console.log("✅ Read about.json successfully");
// 3. Delete existing AboutUs documents (Singleton pattern)
await AboutUs.deleteMany({});
console.log("✅ Cleared existing AboutUs collection");
// 4. Create new AboutUs document with JSON data
const newAboutUs = new AboutUs(jsonData);
await newAboutUs.save();
console.log("✅ Successfully migrated about.json data to MongoDB");
} catch (error) {
console.error("❌ Migration failed:", error.message);
} finally {
// 5. Close connection
await mongoose.connection.close();
console.log("👋 Database connection closed");
process.exit(0);
}
};
migrate();