2026-01-21 13:42:01 +09:00
|
|
|
/**
|
|
|
|
|
* 스케줄 서비스
|
|
|
|
|
* 스케줄 관련 비즈니스 로직
|
|
|
|
|
*/
|
2026-01-24 15:04:29 +09:00
|
|
|
import config, { CATEGORY_IDS, DEBUT_DATE } from '../config/index.js';
|
2026-01-21 16:16:09 +09:00
|
|
|
import { getOrSet, cacheKeys, TTL } from '../utils/cache.js';
|
2026-01-21 13:42:01 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// ==================== 공통 포맷팅 함수 ====================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 날짜 문자열 정규화
|
|
|
|
|
* @param {Date|string} date - 날짜
|
|
|
|
|
* @returns {string} YYYY-MM-DD 형식
|
|
|
|
|
*/
|
|
|
|
|
export function normalizeDate(date) {
|
|
|
|
|
if (!date) return '';
|
|
|
|
|
if (date instanceof Date) {
|
|
|
|
|
return date.toISOString().split('T')[0];
|
|
|
|
|
}
|
|
|
|
|
return String(date).split('T')[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* datetime 생성 (date + time)
|
|
|
|
|
* @param {Date|string} date - 날짜
|
|
|
|
|
* @param {string} time - 시간 (HH:mm:ss)
|
|
|
|
|
* @returns {string} YYYY-MM-DDTHH:mm:ss 또는 YYYY-MM-DD
|
|
|
|
|
*/
|
|
|
|
|
export function buildDatetime(date, time) {
|
|
|
|
|
const dateStr = normalizeDate(date);
|
|
|
|
|
return time ? `${dateStr}T${time}` : dateStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* source 객체 생성
|
|
|
|
|
* @param {object} schedule - 일정 원본 데이터
|
|
|
|
|
* @returns {object|null} { name, url } 또는 null
|
|
|
|
|
*/
|
|
|
|
|
export function buildSource(schedule) {
|
|
|
|
|
const { category_id, youtube_video_id, youtube_video_type, youtube_channel, x_post_id } = schedule;
|
|
|
|
|
|
|
|
|
|
if (category_id === CATEGORY_IDS.YOUTUBE && youtube_video_id) {
|
|
|
|
|
const url = youtube_video_type === 'shorts'
|
|
|
|
|
? `https://www.youtube.com/shorts/${youtube_video_id}`
|
|
|
|
|
: `https://www.youtube.com/watch?v=${youtube_video_id}`;
|
|
|
|
|
return {
|
|
|
|
|
name: youtube_channel || 'YouTube',
|
|
|
|
|
url,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (category_id === CATEGORY_IDS.X && x_post_id) {
|
|
|
|
|
return {
|
|
|
|
|
name: '',
|
|
|
|
|
url: `https://x.com/${config.x.defaultUsername}/status/${x_post_id}`,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 단일 일정 포맷팅 (공통)
|
|
|
|
|
* @param {object} rawSchedule - DB에서 조회한 원본 일정
|
|
|
|
|
* @param {string[]} members - 멤버 이름 배열
|
|
|
|
|
* @returns {object} 포맷된 일정 객체
|
|
|
|
|
*/
|
|
|
|
|
export function formatSchedule(rawSchedule, members = []) {
|
|
|
|
|
return {
|
|
|
|
|
id: rawSchedule.id,
|
|
|
|
|
title: rawSchedule.title,
|
2026-01-24 10:11:02 +09:00
|
|
|
date: normalizeDate(rawSchedule.date),
|
|
|
|
|
time: rawSchedule.time || null,
|
2026-01-21 23:18:48 +09:00
|
|
|
category: {
|
|
|
|
|
id: rawSchedule.category_id,
|
|
|
|
|
name: rawSchedule.category_name,
|
|
|
|
|
color: rawSchedule.category_color,
|
|
|
|
|
},
|
|
|
|
|
source: buildSource(rawSchedule),
|
|
|
|
|
members,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 20:42:05 +09:00
|
|
|
/**
|
|
|
|
|
* 현재 활동 멤버 수 조회
|
|
|
|
|
* @param {object} db - 데이터베이스 연결
|
|
|
|
|
* @returns {number} 현재 활동 멤버 수
|
|
|
|
|
*/
|
|
|
|
|
async function getActiveMemberCount(db) {
|
|
|
|
|
const [[{ count }]] = await db.query(
|
|
|
|
|
'SELECT COUNT(*) as count FROM members WHERE is_former = 0'
|
|
|
|
|
);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
/**
|
|
|
|
|
* 멤버 맵 조회 (일정 ID → 멤버 이름 배열)
|
2026-01-22 20:42:05 +09:00
|
|
|
* 전체 멤버인 경우 "프로미스나인"으로 대체
|
2026-01-21 23:18:48 +09:00
|
|
|
* @param {object} db - 데이터베이스 연결
|
|
|
|
|
* @param {number[]} scheduleIds - 일정 ID 배열
|
|
|
|
|
* @returns {object} { scheduleId: [memberName, ...] }
|
|
|
|
|
*/
|
|
|
|
|
export async function buildMemberMap(db, scheduleIds) {
|
|
|
|
|
if (!scheduleIds || scheduleIds.length === 0) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 20:42:05 +09:00
|
|
|
// 현재 활동 멤버 수 조회
|
|
|
|
|
const activeMemberCount = await getActiveMemberCount(db);
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
const [scheduleMembers] = await db.query(`
|
|
|
|
|
SELECT sm.schedule_id, m.name
|
|
|
|
|
FROM schedule_members sm
|
|
|
|
|
JOIN members m ON sm.member_id = m.id
|
2026-01-22 20:42:05 +09:00
|
|
|
WHERE sm.schedule_id IN (?) AND m.is_former = 0
|
2026-01-21 23:18:48 +09:00
|
|
|
ORDER BY m.id
|
|
|
|
|
`, [scheduleIds]);
|
|
|
|
|
|
|
|
|
|
const memberMap = {};
|
|
|
|
|
for (const sm of scheduleMembers) {
|
|
|
|
|
if (!memberMap[sm.schedule_id]) {
|
|
|
|
|
memberMap[sm.schedule_id] = [];
|
|
|
|
|
}
|
|
|
|
|
memberMap[sm.schedule_id].push(sm.name);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 20:42:05 +09:00
|
|
|
// 전체 멤버인 경우 "프로미스나인"으로 대체
|
|
|
|
|
for (const scheduleId of Object.keys(memberMap)) {
|
|
|
|
|
if (memberMap[scheduleId].length === activeMemberCount) {
|
|
|
|
|
memberMap[scheduleId] = ['프로미스나인'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
return memberMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 일정 목록 포맷팅 (공통)
|
|
|
|
|
* @param {object[]} rawSchedules - DB에서 조회한 원본 일정 배열
|
|
|
|
|
* @param {object} memberMap - 멤버 맵
|
|
|
|
|
* @returns {object[]} 포맷된 일정 배열
|
|
|
|
|
*/
|
|
|
|
|
export function formatSchedules(rawSchedules, memberMap) {
|
|
|
|
|
return rawSchedules.map(s => formatSchedule(s, memberMap[s.id] || []));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== 카테고리 ====================
|
|
|
|
|
|
2026-01-21 16:02:44 +09:00
|
|
|
/**
|
2026-01-21 16:16:09 +09:00
|
|
|
* 카테고리 목록 조회 (캐시 적용)
|
2026-01-21 16:02:44 +09:00
|
|
|
* @param {object} db - 데이터베이스 연결
|
2026-01-21 16:16:09 +09:00
|
|
|
* @param {object} redis - Redis 클라이언트 (선택적)
|
2026-01-21 16:02:44 +09:00
|
|
|
* @returns {array} 카테고리 목록
|
|
|
|
|
*/
|
2026-01-21 16:16:09 +09:00
|
|
|
export async function getCategories(db, redis = null) {
|
|
|
|
|
const fetchCategories = async () => {
|
|
|
|
|
const [categories] = await db.query(
|
|
|
|
|
'SELECT id, name, color, sort_order FROM schedule_categories ORDER BY sort_order ASC, id ASC'
|
|
|
|
|
);
|
|
|
|
|
return categories;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (redis) {
|
|
|
|
|
return getOrSet(redis, cacheKeys.categories, fetchCategories, TTL.VERY_LONG);
|
|
|
|
|
}
|
|
|
|
|
return fetchCategories();
|
2026-01-21 16:02:44 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// ==================== 일정 상세 ====================
|
|
|
|
|
|
2026-01-21 16:02:44 +09:00
|
|
|
/**
|
|
|
|
|
* 일정 상세 조회
|
|
|
|
|
* @param {object} db - 데이터베이스 연결
|
|
|
|
|
* @param {number} id - 일정 ID
|
|
|
|
|
* @param {Function} getXProfile - X 프로필 조회 함수 (선택적)
|
|
|
|
|
* @returns {object|null} 일정 상세 또는 null
|
|
|
|
|
*/
|
|
|
|
|
export async function getScheduleDetail(db, id, getXProfile = null) {
|
|
|
|
|
const [schedules] = await db.query(`
|
|
|
|
|
SELECT
|
|
|
|
|
s.*,
|
|
|
|
|
c.name as category_name,
|
|
|
|
|
c.color as category_color,
|
|
|
|
|
sy.channel_name as youtube_channel,
|
|
|
|
|
sy.video_id as youtube_video_id,
|
|
|
|
|
sy.video_type as youtube_video_type,
|
|
|
|
|
sx.post_id as x_post_id,
|
|
|
|
|
sx.content as x_content,
|
|
|
|
|
sx.image_urls as x_image_urls
|
|
|
|
|
FROM schedules s
|
|
|
|
|
LEFT JOIN schedule_categories c ON s.category_id = c.id
|
|
|
|
|
LEFT JOIN schedule_youtube sy ON s.id = sy.schedule_id
|
|
|
|
|
LEFT JOIN schedule_x sx ON s.id = sx.schedule_id
|
|
|
|
|
WHERE s.id = ?
|
|
|
|
|
`, [id]);
|
|
|
|
|
|
|
|
|
|
if (schedules.length === 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const s = schedules[0];
|
|
|
|
|
|
2026-01-22 20:42:05 +09:00
|
|
|
// 현재 활동 멤버 수 조회
|
|
|
|
|
const activeMemberCount = await getActiveMemberCount(db);
|
|
|
|
|
|
|
|
|
|
// 멤버 정보 조회 (탈퇴 멤버 제외)
|
2026-01-21 16:02:44 +09:00
|
|
|
const [members] = await db.query(`
|
|
|
|
|
SELECT m.id, m.name
|
|
|
|
|
FROM schedule_members sm
|
|
|
|
|
JOIN members m ON sm.member_id = m.id
|
2026-01-22 20:42:05 +09:00
|
|
|
WHERE sm.schedule_id = ? AND m.is_former = 0
|
2026-01-21 16:02:44 +09:00
|
|
|
ORDER BY m.id
|
|
|
|
|
`, [id]);
|
|
|
|
|
|
2026-01-22 20:42:05 +09:00
|
|
|
// 전체 멤버인 경우 "프로미스나인"으로 대체
|
|
|
|
|
const formattedMembers = members.length === activeMemberCount
|
|
|
|
|
? [{ id: 0, name: '프로미스나인' }]
|
|
|
|
|
: members;
|
|
|
|
|
|
2026-01-21 16:02:44 +09:00
|
|
|
// 공통 필드
|
|
|
|
|
const result = {
|
|
|
|
|
id: s.id,
|
|
|
|
|
title: s.title,
|
2026-01-24 10:11:02 +09:00
|
|
|
date: normalizeDate(s.date),
|
|
|
|
|
time: s.time || null,
|
2026-01-21 16:02:44 +09:00
|
|
|
category: {
|
|
|
|
|
id: s.category_id,
|
|
|
|
|
name: s.category_name,
|
|
|
|
|
color: s.category_color,
|
|
|
|
|
},
|
2026-01-22 20:42:05 +09:00
|
|
|
members: formattedMembers,
|
2026-01-21 16:02:44 +09:00
|
|
|
createdAt: s.created_at,
|
|
|
|
|
updatedAt: s.updated_at,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 카테고리별 추가 필드
|
|
|
|
|
if (s.category_id === CATEGORY_IDS.YOUTUBE && s.youtube_video_id) {
|
|
|
|
|
result.videoId = s.youtube_video_id;
|
|
|
|
|
result.videoType = s.youtube_video_type;
|
|
|
|
|
result.channelName = s.youtube_channel;
|
|
|
|
|
result.videoUrl = s.youtube_video_type === 'shorts'
|
|
|
|
|
? `https://www.youtube.com/shorts/${s.youtube_video_id}`
|
|
|
|
|
: `https://www.youtube.com/watch?v=${s.youtube_video_id}`;
|
|
|
|
|
} else if (s.category_id === CATEGORY_IDS.X && s.x_post_id) {
|
|
|
|
|
const username = config.x.defaultUsername;
|
|
|
|
|
result.postId = s.x_post_id;
|
|
|
|
|
result.content = s.x_content || null;
|
|
|
|
|
result.imageUrls = s.x_image_urls ? JSON.parse(s.x_image_urls) : [];
|
|
|
|
|
result.postUrl = `https://x.com/${username}/status/${s.x_post_id}`;
|
|
|
|
|
|
|
|
|
|
if (getXProfile) {
|
|
|
|
|
const profile = await getXProfile(username);
|
|
|
|
|
if (profile) {
|
|
|
|
|
result.profile = {
|
|
|
|
|
username: profile.username,
|
|
|
|
|
displayName: profile.displayName,
|
|
|
|
|
avatarUrl: profile.avatarUrl,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// ==================== 일정 목록 조회 ====================
|
|
|
|
|
|
|
|
|
|
/** 일정 목록 조회용 공통 SQL */
|
|
|
|
|
const SCHEDULE_LIST_SQL = `
|
|
|
|
|
SELECT
|
|
|
|
|
s.id,
|
|
|
|
|
s.title,
|
|
|
|
|
s.date,
|
|
|
|
|
s.time,
|
|
|
|
|
s.category_id,
|
|
|
|
|
c.name as category_name,
|
|
|
|
|
c.color as category_color,
|
|
|
|
|
sy.channel_name as youtube_channel,
|
|
|
|
|
sy.video_id as youtube_video_id,
|
|
|
|
|
sy.video_type as youtube_video_type,
|
|
|
|
|
sx.post_id as x_post_id
|
|
|
|
|
FROM schedules s
|
|
|
|
|
LEFT JOIN schedule_categories c ON s.category_id = c.id
|
|
|
|
|
LEFT JOIN schedule_youtube sy ON s.id = sy.schedule_id
|
|
|
|
|
LEFT JOIN schedule_x sx ON s.id = sx.schedule_id
|
|
|
|
|
`;
|
|
|
|
|
|
2026-01-21 13:42:01 +09:00
|
|
|
/**
|
|
|
|
|
* 월별 일정 조회 (생일 포함)
|
|
|
|
|
* @param {object} db - 데이터베이스 연결
|
|
|
|
|
* @param {number} year - 연도
|
|
|
|
|
* @param {number} month - 월
|
2026-01-21 23:18:48 +09:00
|
|
|
* @returns {object} { schedules: [] }
|
2026-01-21 13:42:01 +09:00
|
|
|
*/
|
|
|
|
|
export async function getMonthlySchedules(db, year, month) {
|
|
|
|
|
const startDate = `${year}-${String(month).padStart(2, '0')}-01`;
|
|
|
|
|
const endDate = new Date(year, month, 0).toISOString().split('T')[0];
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// 일정 조회
|
|
|
|
|
const [rawSchedules] = await db.query(
|
|
|
|
|
`${SCHEDULE_LIST_SQL} WHERE s.date BETWEEN ? AND ? ORDER BY s.date ASC, s.time ASC`,
|
|
|
|
|
[startDate, endDate]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 멤버 맵 조회
|
|
|
|
|
const memberMap = await buildMemberMap(db, rawSchedules.map(s => s.id));
|
|
|
|
|
|
|
|
|
|
// 일정 포맷팅
|
|
|
|
|
const schedules = formatSchedules(rawSchedules, memberMap);
|
2026-01-21 13:42:01 +09:00
|
|
|
|
2026-01-24 15:04:29 +09:00
|
|
|
// 특수 카테고리 조회 (생일, 기념일)
|
|
|
|
|
const [specialCategories] = await db.query(
|
|
|
|
|
'SELECT id, name, color FROM schedule_categories WHERE id IN (?, ?)',
|
|
|
|
|
[CATEGORY_IDS.BIRTHDAY, CATEGORY_IDS.DEBUT]
|
|
|
|
|
);
|
|
|
|
|
const categoryMap = {};
|
|
|
|
|
for (const cat of specialCategories) {
|
|
|
|
|
categoryMap[cat.id] = { id: cat.id, name: cat.name, color: cat.color };
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// 생일 조회 및 추가
|
2026-01-21 13:42:01 +09:00
|
|
|
const [birthdays] = await db.query(`
|
|
|
|
|
SELECT m.id, m.name, m.name_en, m.birth_date,
|
|
|
|
|
i.thumb_url as image_url
|
|
|
|
|
FROM members m
|
|
|
|
|
LEFT JOIN images i ON m.image_id = i.id
|
|
|
|
|
WHERE m.is_former = 0 AND MONTH(m.birth_date) = ?
|
|
|
|
|
`, [month]);
|
|
|
|
|
|
|
|
|
|
for (const member of birthdays) {
|
|
|
|
|
const birthDate = new Date(member.birth_date);
|
2026-01-21 23:18:48 +09:00
|
|
|
if (year < birthDate.getFullYear()) continue;
|
2026-01-21 13:42:01 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
const birthdayDate = new Date(year, birthDate.getMonth(), birthDate.getDate());
|
2026-01-21 13:42:01 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
schedules.push({
|
2026-01-21 13:42:01 +09:00
|
|
|
id: `birthday-${member.id}`,
|
|
|
|
|
title: `HAPPY ${member.name_en} DAY`,
|
2026-01-24 10:11:02 +09:00
|
|
|
date: birthdayDate.toISOString().split('T')[0],
|
|
|
|
|
time: null,
|
2026-01-24 15:04:29 +09:00
|
|
|
category: categoryMap[CATEGORY_IDS.BIRTHDAY],
|
refactor(backend): 일정 API 응답 형식을 검색 API와 통일
변경 사항:
- getMonthlySchedules: 날짜별 그룹화 → 플랫 배열
- getUpcomingSchedules: 날짜별 그룹화 → 플랫 배열
새 형식:
{
"schedules": [
{
"id": 123,
"title": "...",
"datetime": "2025-01-21T19:00:00",
"category": { "id": 1, "name": "...", "color": "#..." },
"source": { "name": "...", "url": "..." },
"members": ["name1", "name2"]
}
]
}
주요 변경:
- date/time 분리 → datetime 통합
- members: [{ name: "..." }] → ["name1", "name2"]
- categories 카운트 제거
- _rankingScore 없음 (검색 API에만 존재)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 20:47:40 +09:00
|
|
|
source: null,
|
|
|
|
|
members: [member.name],
|
2026-01-21 13:42:01 +09:00
|
|
|
is_birthday: true,
|
|
|
|
|
member_image: member.image_url,
|
2026-01-21 23:18:48 +09:00
|
|
|
});
|
2026-01-21 13:42:01 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-24 15:04:29 +09:00
|
|
|
// 데뷔/주년 추가 (1월인 경우)
|
|
|
|
|
if (month === DEBUT_DATE.month) {
|
|
|
|
|
const debutYear = DEBUT_DATE.year;
|
|
|
|
|
const anniversaryYear = year - debutYear;
|
|
|
|
|
|
|
|
|
|
if (year >= debutYear) {
|
|
|
|
|
const debutDate = new Date(year, DEBUT_DATE.month - 1, DEBUT_DATE.day);
|
|
|
|
|
|
|
|
|
|
if (year === debutYear) {
|
|
|
|
|
// 데뷔 당일
|
|
|
|
|
schedules.push({
|
|
|
|
|
id: 'debut',
|
|
|
|
|
title: '프로미스나인 데뷔',
|
|
|
|
|
date: debutDate.toISOString().split('T')[0],
|
|
|
|
|
time: null,
|
|
|
|
|
category: categoryMap[CATEGORY_IDS.DEBUT],
|
|
|
|
|
source: null,
|
|
|
|
|
members: ['프로미스나인'],
|
|
|
|
|
is_debut: true,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// N주년
|
|
|
|
|
schedules.push({
|
|
|
|
|
id: `anniversary-${anniversaryYear}`,
|
|
|
|
|
title: `프로미스나인 데뷔 ${anniversaryYear}주년`,
|
|
|
|
|
date: debutDate.toISOString().split('T')[0],
|
|
|
|
|
time: null,
|
|
|
|
|
category: categoryMap[CATEGORY_IDS.DEBUT],
|
|
|
|
|
source: null,
|
|
|
|
|
members: ['프로미스나인'],
|
|
|
|
|
is_anniversary: true,
|
|
|
|
|
anniversary_year: anniversaryYear,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 18:30:51 +09:00
|
|
|
// 날짜순 정렬 (같은 날짜 내에서 특수 일정을 먼저 배치)
|
|
|
|
|
schedules.sort((a, b) => {
|
|
|
|
|
// 날짜 비교
|
|
|
|
|
const dateCompare = a.date.localeCompare(b.date);
|
|
|
|
|
if (dateCompare !== 0) return dateCompare;
|
|
|
|
|
|
|
|
|
|
// 같은 날짜면 특수 일정(생일, 기념일)을 먼저
|
|
|
|
|
const aSpecial = a.is_birthday || a.is_debut || a.is_anniversary;
|
|
|
|
|
const bSpecial = b.is_birthday || b.is_debut || b.is_anniversary;
|
|
|
|
|
if (aSpecial && !bSpecial) return -1;
|
|
|
|
|
if (!aSpecial && bSpecial) return 1;
|
|
|
|
|
|
|
|
|
|
// 둘 다 특수 일정이면 기념일 > 생일 순서
|
|
|
|
|
if (aSpecial && bSpecial) {
|
|
|
|
|
const aDebut = a.is_debut || a.is_anniversary;
|
|
|
|
|
const bDebut = b.is_debut || b.is_anniversary;
|
|
|
|
|
if (aDebut && !bDebut) return -1;
|
|
|
|
|
if (!aDebut && bDebut) return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 시간순 정렬
|
|
|
|
|
if (a.time && b.time) return a.time.localeCompare(b.time);
|
|
|
|
|
if (a.time) return -1;
|
|
|
|
|
if (b.time) return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
refactor(backend): 일정 API 응답 형식을 검색 API와 통일
변경 사항:
- getMonthlySchedules: 날짜별 그룹화 → 플랫 배열
- getUpcomingSchedules: 날짜별 그룹화 → 플랫 배열
새 형식:
{
"schedules": [
{
"id": 123,
"title": "...",
"datetime": "2025-01-21T19:00:00",
"category": { "id": 1, "name": "...", "color": "#..." },
"source": { "name": "...", "url": "..." },
"members": ["name1", "name2"]
}
]
}
주요 변경:
- date/time 분리 → datetime 통합
- members: [{ name: "..." }] → ["name1", "name2"]
- categories 카운트 제거
- _rankingScore 없음 (검색 API에만 존재)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 20:47:40 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
return { schedules };
|
2026-01-21 13:42:01 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-21 23:18:48 +09:00
|
|
|
* 다가오는 일정 조회
|
2026-01-21 13:42:01 +09:00
|
|
|
* @param {object} db - 데이터베이스 연결
|
|
|
|
|
* @param {string} startDate - 시작 날짜
|
|
|
|
|
* @param {number} limit - 조회 개수
|
2026-01-21 23:18:48 +09:00
|
|
|
* @returns {object} { schedules: [] }
|
2026-01-21 13:42:01 +09:00
|
|
|
*/
|
|
|
|
|
export async function getUpcomingSchedules(db, startDate, limit) {
|
2026-01-21 23:18:48 +09:00
|
|
|
// 일정 조회
|
|
|
|
|
const [rawSchedules] = await db.query(
|
|
|
|
|
`${SCHEDULE_LIST_SQL} WHERE s.date >= ? ORDER BY s.date ASC, s.time ASC LIMIT ?`,
|
|
|
|
|
[startDate, limit]
|
|
|
|
|
);
|
2026-01-21 13:42:01 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// 멤버 맵 조회
|
|
|
|
|
const memberMap = await buildMemberMap(db, rawSchedules.map(s => s.id));
|
2026-01-21 20:10:26 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
// 일정 포맷팅
|
|
|
|
|
const schedules = formatSchedules(rawSchedules, memberMap);
|
2026-01-21 20:10:26 +09:00
|
|
|
|
2026-01-21 23:18:48 +09:00
|
|
|
return { schedules };
|
2026-01-21 13:42:01 +09:00
|
|
|
}
|