2026-01-21 17:22:38 +09:00
|
|
|
/**
|
|
|
|
|
* 스케줄 관련 유틸리티 함수
|
|
|
|
|
*/
|
2026-01-22 14:25:20 +09:00
|
|
|
import { extractDate, extractTime } from './date';
|
2026-01-21 17:22:38 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 스케줄에서 카테고리 ID 추출
|
|
|
|
|
* 검색 결과와 일반 데이터의 형식 차이를 처리
|
|
|
|
|
* @param {object} schedule - 스케줄 객체
|
|
|
|
|
* @returns {number|null} 카테고리 ID
|
|
|
|
|
*/
|
|
|
|
|
export function getCategoryId(schedule) {
|
|
|
|
|
return schedule.category?.id ?? schedule.category_id ?? schedule.categoryId ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 스케줄에서 카테고리 정보 추출
|
|
|
|
|
* @param {object} schedule - 스케줄 객체
|
|
|
|
|
* @returns {{ id: number, name: string, color: string }}
|
|
|
|
|
*/
|
|
|
|
|
export function getCategoryInfo(schedule) {
|
|
|
|
|
return {
|
|
|
|
|
id: getCategoryId(schedule),
|
|
|
|
|
name: schedule.category?.name ?? schedule.category_name ?? schedule.categoryName ?? '미분류',
|
|
|
|
|
color: schedule.category?.color ?? schedule.category_color ?? schedule.categoryColor ?? '#9CA3AF',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 스케줄에서 날짜 추출
|
|
|
|
|
* datetime 형식과 date 형식 모두 처리
|
|
|
|
|
* @param {object} schedule - 스케줄 객체
|
|
|
|
|
* @returns {string} YYYY-MM-DD 형식 날짜
|
|
|
|
|
*/
|
|
|
|
|
export function getScheduleDate(schedule) {
|
2026-01-22 14:25:20 +09:00
|
|
|
return schedule.date || extractDate(schedule.datetime);
|
2026-01-21 17:22:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 스케줄에서 시간 추출
|
|
|
|
|
* @param {object} schedule - 스케줄 객체
|
|
|
|
|
* @returns {string|null} HH:mm 형식 시간 또는 null
|
|
|
|
|
*/
|
|
|
|
|
export function getScheduleTime(schedule) {
|
|
|
|
|
if (schedule.time) {
|
|
|
|
|
return schedule.time.slice(0, 5);
|
|
|
|
|
}
|
2026-01-22 14:25:20 +09:00
|
|
|
return extractTime(schedule.datetime);
|
2026-01-21 17:22:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-21 20:40:07 +09:00
|
|
|
* 스케줄에서 멤버 이름 목록 추출
|
|
|
|
|
* 다양한 형식 처리 (member_names 문자열, 문자열 배열, 객체 배열)
|
2026-01-21 17:22:38 +09:00
|
|
|
* @param {object} schedule - 스케줄 객체
|
2026-01-21 20:40:07 +09:00
|
|
|
* @returns {string[]} 멤버 이름 배열
|
2026-01-21 17:22:38 +09:00
|
|
|
*/
|
|
|
|
|
export function getMemberList(schedule) {
|
2026-01-21 20:40:07 +09:00
|
|
|
// member_names 문자열이 있으면 사용 (쉼표 구분)
|
|
|
|
|
if (schedule.member_names) {
|
|
|
|
|
return schedule.member_names.split(',').map((n) => n.trim()).filter(Boolean);
|
|
|
|
|
}
|
2026-01-21 17:22:38 +09:00
|
|
|
|
2026-01-21 20:40:07 +09:00
|
|
|
const members = schedule.members || [];
|
2026-01-21 17:22:38 +09:00
|
|
|
if (members.length === 0) return [];
|
|
|
|
|
|
|
|
|
|
// 문자열 배열인 경우 (검색 결과)
|
|
|
|
|
if (typeof members[0] === 'string') {
|
2026-01-21 20:40:07 +09:00
|
|
|
return members.filter(Boolean);
|
2026-01-21 17:22:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 객체 배열인 경우
|
2026-01-21 20:40:07 +09:00
|
|
|
return members.map((m) => m.name).filter(Boolean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 멤버 표시 이름 가져오기 (5명 이상이면 '프로미스나인')
|
|
|
|
|
* @param {object} schedule - 스케줄 객체
|
|
|
|
|
* @returns {string[]} 표시할 멤버 이름 배열
|
|
|
|
|
*/
|
|
|
|
|
export function getDisplayMembers(schedule) {
|
|
|
|
|
const memberList = getMemberList(schedule);
|
|
|
|
|
if (memberList.length >= 5) {
|
|
|
|
|
return ['프로미스나인'];
|
|
|
|
|
}
|
|
|
|
|
return memberList;
|
2026-01-21 17:22:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 생일 스케줄인지 확인
|
|
|
|
|
* @param {object} schedule - 스케줄 객체
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
export function isBirthdaySchedule(schedule) {
|
|
|
|
|
const title = schedule.title || '';
|
|
|
|
|
return title.includes('생일') || title.includes('birthday');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 날짜별로 스케줄 그룹화
|
|
|
|
|
* @param {Array} schedules - 스케줄 배열
|
|
|
|
|
* @returns {Map<string, Array>} 날짜별 그룹화된 맵
|
|
|
|
|
*/
|
|
|
|
|
export function groupSchedulesByDate(schedules) {
|
|
|
|
|
const groups = new Map();
|
|
|
|
|
|
|
|
|
|
for (const schedule of schedules) {
|
|
|
|
|
const date = getScheduleDate(schedule);
|
|
|
|
|
if (!groups.has(date)) {
|
|
|
|
|
groups.set(date, []);
|
|
|
|
|
}
|
|
|
|
|
groups.get(date).push(schedule);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 카테고리별 스케줄 수 계산
|
|
|
|
|
* @param {Array} schedules - 스케줄 배열
|
|
|
|
|
* @returns {Map<number, number>} 카테고리 ID별 개수
|
|
|
|
|
*/
|
|
|
|
|
export function countByCategory(schedules) {
|
|
|
|
|
const counts = new Map();
|
|
|
|
|
|
|
|
|
|
for (const schedule of schedules) {
|
|
|
|
|
const categoryId = getCategoryId(schedule);
|
|
|
|
|
counts.set(categoryId, (counts.get(categoryId) || 0) + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return counts;
|
|
|
|
|
}
|