Adding backend of Student Support, Contact, Request

This commit is contained in:
2026-04-20 16:22:37 +07:00
parent fab72e86a6
commit ac5fa14c97
23 changed files with 3167 additions and 2324 deletions
+58
View File
@@ -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 };