forked from UKSOURCE/cms.hailearning.edu.vn
Merge branch 'main' of https://gits.techvanguard.vn/UKSOURCE/cms.hailearning.edu.vn into fea/bao-03022026-Admin-Management-Service
This commit is contained in:
38
scripts/2025_12_02_114127_contact.js
Normal file
38
scripts/2025_12_02_114127_contact.js
Normal file
@@ -0,0 +1,38 @@
|
||||
require("dotenv").config();
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const connectDB = require("../config/database");
|
||||
const Contact = require("../models/contact");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
/**
|
||||
* Migration: contact
|
||||
* Migrate contact data from contact-data.json
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
|
||||
// Read contact-data.json file
|
||||
const contactJsonPath = path.join(__dirname, "../data/contact.json");
|
||||
const contactData = JSON.parse(await fs.readFile(contactJsonPath, "utf8"));
|
||||
|
||||
// Migrate data using the model's static method
|
||||
await Contact.migrateFromJson(contactData);
|
||||
|
||||
console.log("Contact migration completed successfully");
|
||||
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Migration error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Chạy migration nếu được gọi trực tiếp
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
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