forked from UKSOURCE/cms.lams
Adding backend of Student Support, Contact, Request
This commit is contained in:
@@ -21,7 +21,7 @@ async function migrate() {
|
||||
console.log("✅ Home model registered successfully");
|
||||
|
||||
// 3) Load JSON data
|
||||
const dataPath = path.join(__dirname, "..", "..", "hailearning.edu.vn", "app", "home.json");
|
||||
const dataPath = path.join(__dirname, "..", "data", "home.json");
|
||||
const raw = await fs.readFile(dataPath, "utf8");
|
||||
const homeData = JSON.parse(raw);
|
||||
console.log("📖 Home data loaded from:", dataPath);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
require("dotenv").config();
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const connectDB = require("../config/database");
|
||||
const StudentSupport = require("../models/studentSupport");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
/**
|
||||
* Migration: Student Support page content (slug student-support)
|
||||
* Reads data/student-support.json and upserts MongoDB.
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
const jsonPath = path.join(__dirname, "../data/student-support.json");
|
||||
const raw = await fs.readFile(jsonPath, "utf8");
|
||||
const data = JSON.parse(raw);
|
||||
await StudentSupport.migrateFromJson(data);
|
||||
console.log("Student Support migration completed successfully");
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Student Support migration error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
@@ -0,0 +1,58 @@
|
||||
require("dotenv").config();
|
||||
const connectDB = require("../config/database");
|
||||
const User = require("../models/User");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
/**
|
||||
* Migration: seed_users
|
||||
* Description: Tạo sẵn tài khoản cứng cho login CMS
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
|
||||
const users = [
|
||||
{
|
||||
username: process.env.ADMIN_USERNAME || "admin",
|
||||
email: "admin@cms.local",
|
||||
name: "System Admin",
|
||||
password: process.env.ADMIN_PASSWORD || "admin1234",
|
||||
role: "admin",
|
||||
},
|
||||
{
|
||||
username: "manager",
|
||||
email: "manager@cms.local",
|
||||
name: "Content Manager",
|
||||
password: "manager1234",
|
||||
role: "manager",
|
||||
},
|
||||
];
|
||||
|
||||
for (const item of users) {
|
||||
const existing = await User.findOne({ username: item.username });
|
||||
if (existing) {
|
||||
console.log(`SKIP user exists: ${item.username}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
await User.create(item);
|
||||
console.log(`DONE created user: ${item.username}`);
|
||||
}
|
||||
|
||||
console.log("User seed migration completed.");
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("User seed migration failed:", error);
|
||||
if (mongoose.connection.readyState === 1) {
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
@@ -0,0 +1,33 @@
|
||||
require("dotenv").config();
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const connectDB = require("../config/database");
|
||||
const RequestInfo = require("../models/requestInfo");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
/**
|
||||
* Migration: Request Info page content (slug: request-info)
|
||||
* Reads data/request-info.json and upserts into MongoDB.
|
||||
* Idempotent — safe to re-run.
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
const jsonPath = path.join(__dirname, "../data/request-info.json");
|
||||
const raw = await fs.readFile(jsonPath, "utf8");
|
||||
const data = JSON.parse(raw);
|
||||
await RequestInfo.migrateFromJson(data);
|
||||
console.log("Request Info migration completed successfully");
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Request Info migration error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
@@ -0,0 +1,33 @@
|
||||
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 page content (slug: contact)
|
||||
* Reads data/contact.json and upserts into MongoDB.
|
||||
* Idempotent — safe to re-run.
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
const jsonPath = path.join(__dirname, "../data/contact.json");
|
||||
const raw = await fs.readFile(jsonPath, "utf8");
|
||||
const data = JSON.parse(raw);
|
||||
await Contact.migrateFromJson(data);
|
||||
console.log("Contact migration completed successfully");
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Contact migration error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
Reference in New Issue
Block a user