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

refactor: 내 미팅/ 전체 미팅 조회 서비스 수정

parent 110c8109
No related branches found
No related tags found
1 merge request!42[#25] 배포코드 master브랜치로 이동
...@@ -314,130 +314,139 @@ class MeetingService { ...@@ -314,130 +314,139 @@ class MeetingService {
async getMeetings(userId, pagination) { async getMeetings(userId, pagination) {
const { limit = 20, offset = 0 } = pagination; const { limit = 20, offset = 0 } = pagination;
const meetings = await Meeting.findAll({
attributes: [
'id',
'title',
'description',
'time_idx_start',
'time_idx_end',
'location',
'time_idx_deadline',
'type',
'max_num',
'cur_num',
],
include: [
{
model: MeetingParticipant,
as: 'participants',
required: false,
attributes: [],
},
{
model: User,
as: 'creator',
attributes: ['name'],
}
],
order: [['createdAt', 'DESC']],
offset
});
const hasNext = meetings.length > limit; try {
const content = await Promise.all( const meetings = await Meeting.findAll({
meetings.slice(0, limit).map(async (meeting) => { attributes: [
const isParticipant = await MeetingParticipant.findOne({ 'id', 'title', 'description',
where: { 'time_idx_start', 'time_idx_end',
meeting_id: meeting.id, 'location', 'time_idx_deadline',
user_id: userId 'type', 'max_num', 'cur_num',
'created_at'
],
include: [
{
model: MeetingParticipant,
as: 'participants',
required: false,
where: { user_id: userId },
attributes: []
},
{
model: User,
as: 'creator',
attributes: ['name'],
required: false
} }
}); ],
where: {
[Op.or]: [
{ created_by: userId },
{ '$participants.meeting_id$': { [Op.col]: 'Meeting.id' } },
{ '$participants.user_id$': userId }
]
},
subQuery: false,
order: [['created_at', 'DESC']],
limit: limit + 1,
offset,
distinct: true
});
const hasConflict = await ScheduleService.checkScheduleOverlapByTime( const hasNext = meetings.length > limit;
userId, const content = await Promise.all(
meeting.time_idx_start, meetings.slice(0, limit).map(async (meeting) => {
meeting.time_idx_end const isParticipant = true;
); const hasConflict = await ScheduleService.checkScheduleOverlapByTime(
userId,
meeting.time_idx_start,
meeting.time_idx_end
);
const creatorName = meeting.creator ? meeting.creator.name : 'Unknown'; return new MeetingResponseDTO(
return new MeetingResponseDTO(meeting, !!isParticipant, hasConflict, creatorName); meeting,
}) isParticipant,
); hasConflict,
meeting.creator?.name || 'Unknown'
);
})
);
return { return { content, hasNext };
content, } catch (error) {
hasNext console.error('getMeetings error:', error);
}; throw new Error('Failed to fetch meetings');
}
} }
async getMyMeetings(userId, pagination) { async getMyMeetings(userId, pagination) {
const { limit = 20, offset = 0 } = pagination; const { limit = 20, offset = 0 } = pagination;
const meetings = await Meeting.findAll({ try {
attributes: [ const meetings = await Meeting.findAll({
'id', attributes: [
'title', 'id', 'title', 'description', 'time_idx_start',
'description', 'time_idx_end', 'location', 'time_idx_deadline',
'time_idx_start', 'type', 'max_num', 'cur_num',
'time_idx_end', ],
'location', include: [
'time_idx_deadline', {
'type', model: MeetingParticipant,
'max_num', as: 'participants',
'cur_num', required: false,
], attributes: []
include: [ },
{ {
model: MeetingParticipant, model: User,
as: 'participants', as: 'creator',
where: { user_id: userId }, attributes: ['name']
attributes: [], }
],
where: {
[Op.or]: [
{ created_by: userId },
{ '$participants.meeting_id$': { [Op.col]: 'Meeting.id' } },
{ '$participants.user_id$': userId }
]
}, },
{ subQuery: false,
model: User, order: [['created_at', 'DESC']],
as: 'creator', limit: limit + 1,
attributes: ['name'], offset,
} distinct: true
], });
where: {
[Op.or]: [
{ created_by: userId },
{ '$participants.user_id$': userId }
]
},
order: [['createdAt', 'DESC']],
offset
});
const hasNext = meetings.length > limit; const hasNext = meetings.length > limit;
const content = await Promise.all( const content = await Promise.all(
meetings.slice(0, limit).map(async (meeting) => { meetings.slice(0, limit).map(async (meeting) => {
const isParticipant = await MeetingParticipant.findOne({ const isParticipant = await MeetingParticipant.findOne({
where: { where: {
meeting_id: meeting.id, meeting_id: meeting.id,
user_id: userId user_id: userId
} }
}); });
const hasConflict = await ScheduleService.checkScheduleOverlapByTime( const hasConflict = await ScheduleService.checkScheduleOverlapByTime(
userId, userId,
meeting.time_idx_start, meeting.time_idx_start,
meeting.time_idx_end meeting.time_idx_end
); );
const creatorName = meeting.creator ? meeting.creator.name : 'Unknown'; return {
return new MeetingResponseDTO(meeting, !!isParticipant, hasConflict, creatorName); ...meeting.toJSON(),
}) isParticipant: !!isParticipant,
); hasConflict,
creatorName: meeting.creator?.name || 'Unknown'
};
})
);
return { return { content, hasNext };
content, } catch (error) {
hasNext console.error('getMyMeetings error:', error);
}; throw new Error('Failed to fetch my meetings');
}
} }
async getMeetingDetail(meetingId, userId) { async getMeetingDetail(meetingId, userId) {
const meeting = await Meeting.findByPk(meetingId, { const meeting = await Meeting.findByPk(meetingId, {
include: [ include: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment