- datetime 필드를 date와 time 필드로 분리하여 00:00 시간도 정상 표시되도록 수정 - 백엔드: formatSchedule, Meilisearch 검색 결과, 스키마 업데이트 - 프론트엔드: datetime 파싱 로직 제거, date/time 직접 사용 - 문서: API 응답 예시 업데이트 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
121 lines
3.2 KiB
JavaScript
121 lines
3.2 KiB
JavaScript
/**
|
|
* 스케줄 관련 유틸리티 함수
|
|
*/
|
|
import { extractDate, extractTime } from './date';
|
|
|
|
/**
|
|
* 스케줄에서 카테고리 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',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 스케줄에서 날짜 추출
|
|
* @param {object} schedule - 스케줄 객체
|
|
* @returns {string} YYYY-MM-DD 형식 날짜
|
|
*/
|
|
export function getScheduleDate(schedule) {
|
|
return schedule.date || '';
|
|
}
|
|
|
|
/**
|
|
* 스케줄에서 시간 추출
|
|
* @param {object} schedule - 스케줄 객체
|
|
* @returns {string|null} HH:mm 형식 시간 또는 null
|
|
*/
|
|
export function getScheduleTime(schedule) {
|
|
if (schedule.time) {
|
|
return schedule.time.slice(0, 5);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 스케줄에서 멤버 이름 목록 추출
|
|
* @param {object} schedule - 스케줄 객체
|
|
* @returns {string[]} 멤버 이름 배열
|
|
*/
|
|
export function getMemberList(schedule) {
|
|
const members = schedule.members || [];
|
|
if (members.length === 0) return [];
|
|
|
|
// 문자열 배열인 경우 (검색 결과)
|
|
if (typeof members[0] === 'string') {
|
|
return members.filter(Boolean);
|
|
}
|
|
|
|
// 객체 배열인 경우
|
|
return members.map((m) => m.name).filter(Boolean);
|
|
}
|
|
|
|
/**
|
|
* 멤버 표시 이름 가져오기
|
|
* 백엔드에서 전체 멤버인 경우 '프로미스나인'으로 처리함
|
|
* @param {object} schedule - 스케줄 객체
|
|
* @returns {string[]} 표시할 멤버 이름 배열
|
|
*/
|
|
export function getDisplayMembers(schedule) {
|
|
return getMemberList(schedule);
|
|
}
|
|
|
|
/**
|
|
* 생일 스케줄인지 확인
|
|
* @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;
|
|
}
|