Skip to content
Snippets Groups Projects
Commit f4359f42 authored by 조대희's avatar 조대희
Browse files

refactor: 문자열 -> 정수 변환

parent 544cd55d
Branches
No related tags found
1 merge request!43배포코드 master브랜치로
...@@ -119,8 +119,8 @@ class MeetingService { ...@@ -119,8 +119,8 @@ class MeetingService {
); );
const time_indices = Array.from( const time_indices = Array.from(
{ length: time_idx_end - time_idx_start + 1 }, { length: parseInt(time_idx_end) - parseInt(time_idx_start) + 1 },
(_, i) => time_idx_start + i (_, i) => (parseInt(time_idx_start) + i).toString()
); );
await ScheduleService.createSchedules({ await ScheduleService.createSchedules({
userId: created_by, userId: created_by,
......
...@@ -10,11 +10,17 @@ class ScheduleService { ...@@ -10,11 +10,17 @@ class ScheduleService {
* @param {object} [transaction] - Sequelize 트랜잭션 객체 -> 미팅방에서 쓰기위해 트랜잭션을 넘겨받는걸 추가 * @param {object} [transaction] - Sequelize 트랜잭션 객체 -> 미팅방에서 쓰기위해 트랜잭션을 넘겨받는걸 추가
*/ */
async createSchedules({ userId, title, is_fixed, time_indices }, transaction = null) { async createSchedules({ userId, title, is_fixed, time_indices }, transaction = null) {
const parsedTimeIndices = time_indices.map(idx => parseInt(idx, 10));
if (!userId || !title || !parsedTimeIndices.length) {
throw new Error('Required parameters missing');
}
const overlaps = await Schedule.findAll({ const overlaps = await Schedule.findAll({
where: { where: {
user_id: userId, user_id: userId,
time_idx: { time_idx: {
[Op.in]: time_indices [Op.in]: parsedTimeIndices
} }
}, },
transaction transaction
...@@ -24,25 +30,14 @@ class ScheduleService { ...@@ -24,25 +30,14 @@ class ScheduleService {
throw new Error(`Schedule overlaps at time_idx ${overlaps[0].time_idx}`); throw new Error(`Schedule overlaps at time_idx ${overlaps[0].time_idx}`);
} }
const scheduleData = time_indices.map(time_idx => ({ const scheduleData = parsedTimeIndices.map(time_idx => ({
user_id: userId, user_id: userId,
title, title,
time_idx: parseInt(time_idx, 10), time_idx,
is_fixed is_fixed
})); }));
try { try {
if (!userId || !title || !time_indices) {
throw new Error('Required parameters missing');
}
console.log('Creating schedule with data:', {
userId,
title,
is_fixed,
time_indices
});
const createdSchedules = await Schedule.bulkCreate(scheduleData, { const createdSchedules = await Schedule.bulkCreate(scheduleData, {
transaction, transaction,
returning: true, returning: true,
...@@ -54,7 +49,7 @@ class ScheduleService { ...@@ -54,7 +49,7 @@ class ScheduleService {
user_id: userId, user_id: userId,
title, title,
is_fixed, is_fixed,
time_indices, time_indices: parsedTimeIndices,
createdAt: createdSchedules[0].createdAt, createdAt: createdSchedules[0].createdAt,
updatedAt: createdSchedules[0].updatedAt updatedAt: createdSchedules[0].updatedAt
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment