init
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
async function checkDatabaseTables() {
|
||||
try {
|
||||
// 데이터베이스 연결
|
||||
await sequelize.authenticate();
|
||||
console.log('데이터베이스 연결 성공');
|
||||
|
||||
// 모든 테이블 목록 조회
|
||||
const [tables] = await sequelize.query('SHOW TABLES');
|
||||
|
||||
console.log('데이터베이스 테이블 목록:');
|
||||
tables.forEach(table => {
|
||||
const tableName = Object.values(table)[0];
|
||||
console.log(`- ${tableName}`);
|
||||
});
|
||||
|
||||
// 각 테이블의 구조 확인
|
||||
for (const table of tables) {
|
||||
const tableName = Object.values(table)[0];
|
||||
const [columns] = await sequelize.query(`DESCRIBE \`${tableName}\``);
|
||||
|
||||
console.log(`\n테이블: ${tableName}`);
|
||||
columns.forEach(column => {
|
||||
console.log(` - ${column.Field}: ${column.Type} ${column.Null === 'NO' ? 'NOT NULL' : 'NULL'} ${column.Key === 'PRI' ? 'PRIMARY KEY' : ''}`);
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('오류 발생:', error);
|
||||
} finally {
|
||||
// 연결 종료
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 스크립트 실행
|
||||
checkDatabaseTables();
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 기본 클럽 생성 스크립트
|
||||
* 데이터베이스에 기본 클럽을 생성하고 사용자에게 할당합니다.
|
||||
*/
|
||||
const { sequelize } = require('../src/config/database');
|
||||
const Club = require('../src/models/Club');
|
||||
const User = require('../src/models/User');
|
||||
const UserClub = require('../src/models/UserClub');
|
||||
require('dotenv').config();
|
||||
|
||||
async function createDefaultClub() {
|
||||
try {
|
||||
// 데이터베이스 연결 확인
|
||||
await sequelize.authenticate();
|
||||
console.log('데이터베이스 연결 성공');
|
||||
|
||||
// 관리자 사용자 찾기
|
||||
const adminUser = await User.findOne({
|
||||
where: {
|
||||
role: 'admin'
|
||||
}
|
||||
});
|
||||
|
||||
if (!adminUser) {
|
||||
console.log('관리자 사용자를 찾을 수 없습니다. 기본 클럽을 생성할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('관리자 사용자 찾음:', adminUser.email);
|
||||
|
||||
// 기존 클럽 확인
|
||||
const existingClubs = await Club.findAll();
|
||||
|
||||
let defaultClub;
|
||||
|
||||
if (existingClubs.length === 0) {
|
||||
// 기본 클럽 생성
|
||||
defaultClub = await Club.create({
|
||||
name: '볼링 마스터 클럽',
|
||||
description: '볼링 클럽 매니저 기본 클럽입니다.',
|
||||
ownerId: adminUser.id,
|
||||
active: true,
|
||||
subscriptionStatus: '활성',
|
||||
subscriptionType: '기본 구독',
|
||||
subscriptionExpiry: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), // 1년 후
|
||||
memberCount: 1
|
||||
});
|
||||
console.log('기본 클럽 생성 완료:', defaultClub.name);
|
||||
} else {
|
||||
defaultClub = existingClubs[0];
|
||||
console.log('기존 클럽 사용:', defaultClub.name);
|
||||
}
|
||||
|
||||
// 모든 사용자 가져오기
|
||||
const users = await User.findAll();
|
||||
|
||||
// 각 사용자에게 클럽 할당
|
||||
for (const user of users) {
|
||||
// 이미 클럽에 속해 있는지 확인
|
||||
const existingUserClub = await UserClub.findOne({
|
||||
where: {
|
||||
userId: user.id,
|
||||
clubId: defaultClub.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!existingUserClub) {
|
||||
// 사용자-클럽 관계 생성
|
||||
await UserClub.create({
|
||||
userId: user.id,
|
||||
clubId: defaultClub.id,
|
||||
role: user.role === 'admin' || user.role === 'superadmin' ? 'admin' : 'member',
|
||||
joinDate: new Date(),
|
||||
status: 'active'
|
||||
});
|
||||
console.log(`사용자 ${user.email}에게 클럽 할당 완료`);
|
||||
} else {
|
||||
console.log(`사용자 ${user.email}는 이미 클럽에 속해 있습니다.`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('기본 클럽 생성 및 사용자 할당이 완료되었습니다.');
|
||||
console.log('기본 클럽 ID:', defaultClub.id);
|
||||
|
||||
return defaultClub.id;
|
||||
} catch (error) {
|
||||
console.error('기본 클럽 생성 중 오류 발생:', error);
|
||||
} finally {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 스크립트 실행
|
||||
createDefaultClub();
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* 메뉴 생성 스크립트
|
||||
* 데이터베이스에 기본 메뉴 항목을 생성합니다.
|
||||
*/
|
||||
const { Menu } = require('../src/models');
|
||||
const { sequelize } = require('../src/config/database');
|
||||
require('dotenv').config();
|
||||
|
||||
// 관리자용 메뉴 항목
|
||||
const adminMenus = [
|
||||
{
|
||||
title: '대시보드',
|
||||
icon: 'pi pi-home',
|
||||
to: '/admin',
|
||||
role: 'admin',
|
||||
order: 1,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '클럽 관리',
|
||||
icon: 'pi pi-users',
|
||||
to: '/admin/clubs',
|
||||
role: 'admin',
|
||||
order: 2,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '사용자 관리',
|
||||
icon: 'pi pi-user',
|
||||
to: '/admin/users',
|
||||
role: 'admin',
|
||||
order: 3,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '구독 관리',
|
||||
icon: 'pi pi-credit-card',
|
||||
to: '/admin/subscriptions',
|
||||
role: 'admin',
|
||||
order: 4,
|
||||
visible: true
|
||||
}
|
||||
];
|
||||
|
||||
// 일반 사용자용 메뉴 항목
|
||||
const userMenus = [
|
||||
{
|
||||
title: '대시보드',
|
||||
icon: 'pi pi-home',
|
||||
to: '/clubs',
|
||||
role: 'user',
|
||||
order: 1,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '회원 관리',
|
||||
icon: 'pi pi-users',
|
||||
to: '/clubs/members',
|
||||
role: 'user',
|
||||
order: 2,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '모임 관리',
|
||||
icon: 'pi pi-calendar',
|
||||
to: '/clubs/meetings',
|
||||
role: 'user',
|
||||
order: 3,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '점수 관리',
|
||||
icon: 'pi pi-chart-bar',
|
||||
to: '/clubs/meetings/scores',
|
||||
role: 'user',
|
||||
order: 4,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '통계',
|
||||
icon: 'pi pi-chart-line',
|
||||
to: '/statistics',
|
||||
role: 'user',
|
||||
order: 5,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '예약',
|
||||
icon: 'pi pi-bookmark',
|
||||
to: '/clubs/reservations',
|
||||
role: 'user',
|
||||
order: 6,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '이벤트 관리',
|
||||
icon: 'pi pi-list',
|
||||
to: '/clubs/events',
|
||||
role: 'user',
|
||||
order: 7,
|
||||
visible: true
|
||||
},
|
||||
{
|
||||
title: '이벤트 캘린더',
|
||||
icon: 'pi pi-calendar',
|
||||
to: '/clubs/events/calendar',
|
||||
role: 'user',
|
||||
order: 8,
|
||||
visible: true
|
||||
}
|
||||
];
|
||||
|
||||
// 메뉴 생성 함수
|
||||
async function createMenus() {
|
||||
try {
|
||||
// 데이터베이스 연결 확인
|
||||
await sequelize.authenticate();
|
||||
console.log('데이터베이스 연결 성공');
|
||||
|
||||
// 메뉴 테이블 동기화
|
||||
await Menu.sync({ alter: true });
|
||||
console.log('메뉴 테이블 동기화 완료');
|
||||
|
||||
// 기존 메뉴 항목 확인
|
||||
const existingMenus = await Menu.findAll();
|
||||
|
||||
if (existingMenus.length > 0) {
|
||||
console.log('메뉴 항목이 이미 존재합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 관리자용 메뉴 생성
|
||||
for (const menu of adminMenus) {
|
||||
await Menu.create(menu);
|
||||
}
|
||||
console.log('관리자용 메뉴 생성 완료');
|
||||
|
||||
// 일반 사용자용 메뉴 생성
|
||||
for (const menu of userMenus) {
|
||||
await Menu.create(menu);
|
||||
}
|
||||
console.log('일반 사용자용 메뉴 생성 완료');
|
||||
|
||||
console.log('모든 메뉴 항목이 성공적으로 생성되었습니다.');
|
||||
} catch (error) {
|
||||
console.error('메뉴 생성 중 오류 발생:', error);
|
||||
} finally {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 스크립트 실행
|
||||
createMenus();
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* 초기 알림 데이터 생성 스크립트
|
||||
*/
|
||||
require('dotenv').config();
|
||||
const mongoose = require('mongoose');
|
||||
const User = require('../models/User');
|
||||
const Notification = require('../models/Notification');
|
||||
|
||||
// MongoDB 연결
|
||||
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/bowlingManager', {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true
|
||||
})
|
||||
.then(() => console.log('MongoDB 연결 성공'))
|
||||
.catch(err => {
|
||||
console.error('MongoDB 연결 오류:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// 초기 알림 데이터 생성
|
||||
const createNotifications = async () => {
|
||||
try {
|
||||
// 모든 사용자 가져오기
|
||||
const users = await User.find();
|
||||
|
||||
if (users.length === 0) {
|
||||
console.log('사용자가 없습니다. 먼저 사용자를 생성해주세요.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// 기존 알림 삭제
|
||||
await Notification.deleteMany({});
|
||||
console.log('기존 알림 데이터 삭제 완료');
|
||||
|
||||
// 각 사용자에 대한 알림 생성
|
||||
const notificationPromises = users.map(async (user) => {
|
||||
// 알림 타입 및 메시지 배열
|
||||
const notificationTemplates = [
|
||||
{
|
||||
title: '시스템 알림',
|
||||
message: '볼링 클럽 매니저 시스템에 오신 것을 환영합니다.',
|
||||
icon: 'pi pi-info-circle',
|
||||
type: 'info',
|
||||
read: false
|
||||
},
|
||||
{
|
||||
title: '클럽 알림',
|
||||
message: '새로운 클럽 회원이 가입했습니다.',
|
||||
icon: 'pi pi-users',
|
||||
type: 'success',
|
||||
read: false
|
||||
},
|
||||
{
|
||||
title: '예약 알림',
|
||||
message: '레인 예약이 확정되었습니다.',
|
||||
icon: 'pi pi-calendar',
|
||||
type: 'info',
|
||||
read: true
|
||||
},
|
||||
{
|
||||
title: '대회 알림',
|
||||
message: '다음 주 토요일 클럽 대회가 예정되어 있습니다.',
|
||||
icon: 'pi pi-flag',
|
||||
type: 'warning',
|
||||
read: false
|
||||
},
|
||||
{
|
||||
title: '시스템 업데이트',
|
||||
message: '시스템이 업데이트 되었습니다. 새로운 기능을 확인해보세요.',
|
||||
icon: 'pi pi-refresh',
|
||||
type: 'info',
|
||||
read: true
|
||||
}
|
||||
];
|
||||
|
||||
// 사용자별 알림 생성 (시간 차이를 두고)
|
||||
const notifications = notificationTemplates.map((template, index) => {
|
||||
const hoursAgo = (index + 1) * 12; // 12시간, 24시간, 36시간... 간격
|
||||
const createdAt = new Date(Date.now() - (hoursAgo * 3600000));
|
||||
|
||||
return new Notification({
|
||||
user: user._id,
|
||||
title: template.title,
|
||||
message: template.message,
|
||||
icon: template.icon,
|
||||
type: template.type,
|
||||
read: template.read,
|
||||
createdAt
|
||||
});
|
||||
});
|
||||
|
||||
return Notification.insertMany(notifications);
|
||||
});
|
||||
|
||||
await Promise.all(notificationPromises);
|
||||
console.log('알림 데이터 생성 완료');
|
||||
|
||||
// 연결 종료
|
||||
mongoose.connection.close();
|
||||
console.log('MongoDB 연결 종료');
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('알림 데이터 생성 오류:', error);
|
||||
mongoose.connection.close();
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
createNotifications();
|
||||
@@ -0,0 +1,46 @@
|
||||
require('dotenv').config();
|
||||
const { User, syncModels, testConnection } = require('../src/models');
|
||||
|
||||
async function createSuperAdmin() {
|
||||
try {
|
||||
// 데이터베이스 연결 테스트
|
||||
console.log('데이터베이스 연결 테스트 중...');
|
||||
await testConnection();
|
||||
|
||||
// 모델 동기화 (필요한 경우)
|
||||
// console.log('데이터베이스 모델 동기화 중...');
|
||||
// await syncModels();
|
||||
|
||||
// 기존 superadmin 계정 확인
|
||||
const existingAdmin = await User.findOne({
|
||||
where: { email: process.env.ADMIN_EMAIL }
|
||||
});
|
||||
|
||||
if (existingAdmin) {
|
||||
console.log('이미 superadmin 계정이 존재합니다:', existingAdmin.email);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// superadmin 계정 생성
|
||||
const superAdmin = await User.create({
|
||||
username: 'master',
|
||||
password: process.env.ADMIN_PASSWORD,
|
||||
name: '최고관리자',
|
||||
email: process.env.ADMIN_EMAIL,
|
||||
role: 'superadmin',
|
||||
active: true
|
||||
});
|
||||
|
||||
console.log('superadmin 계정이 성공적으로 생성되었습니다:');
|
||||
console.log('- 이메일:', superAdmin.email);
|
||||
console.log('- 역할:', superAdmin.role);
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('superadmin 계정 생성 중 오류 발생:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 스크립트 실행
|
||||
createSuperAdmin();
|
||||
Reference in New Issue
Block a user