메인페이지

This commit is contained in:
mota
2025-11-02 12:07:11 +09:00
parent 11726858cc
commit 2c86f2d515
8 changed files with 458 additions and 187 deletions

View File

@@ -1,7 +1,12 @@
const { PrismaClient } = require("@prisma/client");
const { createHash } = require("crypto");
const prisma = new PrismaClient();
function hashPassword(plain) {
return createHash("sha256").update(plain, "utf8").digest("hex");
}
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@@ -60,12 +65,19 @@ async function createRandomUsers(count = 100) {
name,
birth,
phone,
passwordHash: hashPassword("1234"),
agreementTermsAt: new Date(),
authLevel: "USER",
isAdultVerified: Math.random() < 0.6,
lastLoginAt: Math.random() < 0.8 ? new Date() : null,
},
});
} else {
// 기존 사용자도 패스워드를 1234로 업데이트
await prisma.user.update({
where: { userId: user.userId },
data: { passwordHash: hashPassword("1234") },
});
}
if (roleUser && user) {
await prisma.userRole.upsert({
@@ -83,6 +95,7 @@ async function upsertCategories() {
{ name: "메인", slug: "main", sortOrder: 1, status: "active" },
{ name: "명예의 전당", slug: "hall-of-fame", sortOrder: 2, status: "active" },
{ name: "소통방", slug: "community", sortOrder: 3, status: "active" },
{ name: "TEST", slug: "test", sortOrder: 4, status: "active" },
];
const map = {};
for (const c of categories) {
@@ -155,12 +168,13 @@ async function upsertRoles() {
async function upsertAdmin() {
const admin = await prisma.user.upsert({
where: { nickname: "admin" },
update: {},
update: { passwordHash: hashPassword("1234") },
create: {
nickname: "admin",
name: "Administrator",
birth: new Date("1990-01-01"),
phone: "010-0000-0001",
passwordHash: hashPassword("1234"),
agreementTermsAt: new Date(),
authLevel: "ADMIN",
},
@@ -195,14 +209,17 @@ async function upsertBoards(admin, categoryMap) {
{ name: "회원랭킹", slug: "ranking", description: "랭킹", sortOrder: 14 },
{ name: "무료쿠폰", slug: "free-coupons", description: "쿠폰", sortOrder: 15 },
{ name: "월간집계", slug: "monthly-stats", description: "월간 통계", sortOrder: 16 },
// TEST
{ name: "TEST", slug: "test", description: "테스트 게시판", sortOrder: 20 },
// 광고/제휴 계열 게시판은 제거(메인/명예의전당/소통방 외)
];
const created = [];
// 특수 랭킹/텍스트 뷰 타입 ID 조회 (사전에 upsertViewTypes로 생성됨)
// 특수 랭킹/텍스트/미리보기 뷰 타입 ID 조회 (사전에 upsertViewTypes로 생성됨)
const mainSpecial = await prisma.boardViewType.findUnique({ where: { key: "main_special_rank" } });
const listSpecial = await prisma.boardViewType.findUnique({ where: { key: "list_special_rank" } });
const mainText = await prisma.boardViewType.findUnique({ where: { key: "main_text" } });
const mainPreview = await prisma.boardViewType.findUnique({ where: { key: "main_preview" } });
for (const b of boards) {
// 카테고리 매핑 규칙 (트리 기준 상위 카테고리)
@@ -222,6 +239,8 @@ async function upsertBoards(admin, categoryMap) {
qna: "community",
tips: "community",
anonymous: "community",
// TEST
test: "test",
// 광고/제휴
};
const categorySlug = mapBySlug[b.slug] || "community";
@@ -234,9 +253,11 @@ async function upsertBoards(admin, categoryMap) {
allowAnonymousPost: !!b.allowAnonymousPost,
readLevel: b.readLevel || undefined,
categoryId: category ? category.id : undefined,
// 메인뷰: 기본이 아니라 텍스트(main_text)로 설정, 랭킹 보드는 특수 랭킹 유지
// 메인뷰: 기본이 아니라 텍스트(main_text)로 설정, 랭킹 보드는 특수 랭킹 유지, TEST는 미리보기
...(b.slug === "ranking"
? (mainSpecial ? { mainPageViewTypeId: mainSpecial.id } : {})
: b.slug === "test"
? (mainPreview ? { mainPageViewTypeId: mainPreview.id } : {})
: (mainText ? { mainPageViewTypeId: mainText.id } : {})),
...(b.slug === "ranking" && listSpecial ? { listViewTypeId: listSpecial.id } : {}),
},
@@ -248,9 +269,11 @@ async function upsertBoards(admin, categoryMap) {
allowAnonymousPost: !!b.allowAnonymousPost,
readLevel: b.readLevel || undefined,
categoryId: category ? category.id : undefined,
// 메인뷰: 기본이 아니라 텍스트(main_text)로 설정, 랭킹 보드는 특수 랭킹 유지
// 메인뷰: 기본이 아니라 텍스트(main_text)로 설정, 랭킹 보드는 특수 랭킹 유지, TEST는 미리보기
...(b.slug === "ranking"
? (mainSpecial ? { mainPageViewTypeId: mainSpecial.id } : {})
: b.slug === "test"
? (mainPreview ? { mainPageViewTypeId: mainPreview.id } : {})
: (mainText ? { mainPageViewTypeId: mainText.id } : {})),
...(b.slug === "ranking" && listSpecial ? { listViewTypeId: listSpecial.id } : {}),
},
@@ -393,7 +416,7 @@ async function seedMainpageVisibleBoards(boards) {
const SETTINGS_KEY = "mainpage_settings";
const setting = await prisma.setting.findUnique({ where: { key: SETTINGS_KEY } });
const current = setting ? JSON.parse(setting.value) : {};
const wantSlugs = new Set(["notice", "free", "ranking"]);
const wantSlugs = new Set(["notice", "free", "ranking", "test"]);
const visibleBoardIds = boards.filter((b) => wantSlugs.has(b.slug)).map((b) => b.id);
const next = { ...current, visibleBoardIds };
await prisma.setting.upsert({