forked from UKSOURCE/cms.hailearning.edu.vn
feat: Implement core admin panel functionalities including appointment, contact, and pricing management with associated models, controllers, views, and routes.
This commit is contained in:
71
scripts/2026_02_03_appointment.js
Normal file
71
scripts/2026_02_03_appointment.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Migration script for Appointment data
|
||||
* Imports data from appointment.json to MongoDB
|
||||
*
|
||||
* Run: node scripts/2026_02_03_appointment.js
|
||||
*/
|
||||
|
||||
require("dotenv").config();
|
||||
const mongoose = require("mongoose");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// Connect to MongoDB
|
||||
const connectDB = async () => {
|
||||
try {
|
||||
await mongoose.connect(process.env.MONGODB_URI);
|
||||
console.log("MongoDB connected successfully");
|
||||
} catch (error) {
|
||||
console.error("MongoDB connection error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
const runMigration = async () => {
|
||||
try {
|
||||
await connectDB();
|
||||
|
||||
// Load Appointment model
|
||||
const Appointment = require("../models/appointment");
|
||||
|
||||
// Load JSON data
|
||||
const jsonPath = path.join(__dirname, "../data/appointment.json");
|
||||
|
||||
if (!fs.existsSync(jsonPath)) {
|
||||
console.log("appointment.json not found, creating default data...");
|
||||
const defaultData = {
|
||||
hero: {
|
||||
title: "Make Appointment",
|
||||
backgroundImage: "",
|
||||
subtitle: "",
|
||||
heading: "",
|
||||
description: "",
|
||||
},
|
||||
visaOptions: [],
|
||||
form: {
|
||||
heading: "Request Appointment",
|
||||
fields: [],
|
||||
submitButton: {
|
||||
text: "Request Appointment",
|
||||
icon: "fa-solid fa-arrow-right",
|
||||
buttonClass: "theme-btn",
|
||||
},
|
||||
},
|
||||
};
|
||||
await Appointment.migrateFromJson(defaultData);
|
||||
} else {
|
||||
const jsonData = JSON.parse(fs.readFileSync(jsonPath, "utf8"));
|
||||
console.log("Loaded appointment.json data");
|
||||
await Appointment.migrateFromJson(jsonData);
|
||||
}
|
||||
|
||||
console.log("✅ Appointment migration completed successfully!");
|
||||
} catch (error) {
|
||||
console.error("❌ Migration failed:", error);
|
||||
} finally {
|
||||
await mongoose.connection.close();
|
||||
console.log("MongoDB connection closed");
|
||||
}
|
||||
};
|
||||
|
||||
runMigration();
|
||||
Reference in New Issue
Block a user