출석관련
Some checks failed
deploy-on-main / deploy (push) Failing after 22s

This commit is contained in:
koreacomp5
2025-11-10 01:56:44 +09:00
parent b579b32138
commit 5485da4029
4 changed files with 145 additions and 68 deletions

View File

@@ -119,6 +119,7 @@ async function createRandomUsers(count = 100) {
}
}
const createdUsers = [];
for (let i = 0; i < count; i++) {
// 닉네임을 결정론적으로 생성해 재실행 시 중복 생성 방지
const nickname = `user${String(i + 1).padStart(3, "0")}`;
@@ -155,7 +156,9 @@ async function createRandomUsers(count = 100) {
create: { userId: user.userId, roleId: roleUser.roleId },
});
}
if (user) createdUsers.push(user);
}
return createdUsers;
}
async function upsertCategories() {
@@ -289,6 +292,36 @@ async function seedAdminAttendance(admin) {
}
}
async function seedRandomAttendanceForUsers(users, minDays = 10, maxDays = 20) {
try {
const today = new Date();
const todayUtcMidnight = new Date(Date.UTC(
today.getUTCFullYear(),
today.getUTCMonth(),
today.getUTCDate(),
0, 0, 0, 0
));
for (const user of users) {
const count = randomInt(minDays, maxDays);
const used = new Set();
while (used.size < count) {
const offsetDays = randomInt(0, 120); // 최근 120일 범위에서 랜덤
const date = new Date(todayUtcMidnight.getTime() - offsetDays * 24 * 60 * 60 * 1000);
const key = date.toISOString().slice(0, 10); // YYYY-MM-DD
if (used.has(key)) continue;
used.add(key);
await prisma.attendance.upsert({
where: { userId_date: { userId: user.userId, date } },
update: {},
create: { userId: user.userId, date },
});
}
}
} catch (e) {
console.warn("seedRandomAttendanceForUsers failed:", e);
}
}
async function upsertBoards(admin, categoryMap) {
const boards = [
// 일반
@@ -600,7 +633,8 @@ async function main() {
const admin = await upsertAdmin();
const categoryMap = await upsertCategories();
await upsertViewTypes();
await createRandomUsers(100);
const randomUsers = await createRandomUsers(3);
await seedRandomAttendanceForUsers(randomUsers, 10, 20);
await removeNonPrimaryBoards();
const boards = await upsertBoards(admin, categoryMap);
await seedAdminAttendance(admin);