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브랜치로 이동
...@@ -315,100 +315,105 @@ class MeetingService { ...@@ -315,100 +315,105 @@ class MeetingService {
async getMeetings(userId, pagination) { async getMeetings(userId, pagination) {
const { limit = 20, offset = 0 } = pagination; const { limit = 20, offset = 0 } = pagination;
try {
const meetings = await Meeting.findAll({ const meetings = await Meeting.findAll({
attributes: [ attributes: [
'id', 'id', 'title', 'description',
'title', 'time_idx_start', 'time_idx_end',
'description', 'location', 'time_idx_deadline',
'time_idx_start', 'type', 'max_num', 'cur_num',
'time_idx_end', 'created_at'
'location',
'time_idx_deadline',
'type',
'max_num',
'cur_num',
], ],
include: [ include: [
{ {
model: MeetingParticipant, model: MeetingParticipant,
as: 'participants', as: 'participants',
required: false, required: false,
attributes: [], where: { user_id: userId },
attributes: []
}, },
{ {
model: User, model: User,
as: 'creator', as: 'creator',
attributes: ['name'], attributes: ['name'],
required: false
} }
], ],
order: [['createdAt', 'DESC']], where: {
offset [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 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 = true;
where: {
meeting_id: meeting.id,
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 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;
try {
const meetings = await Meeting.findAll({ const meetings = await Meeting.findAll({
attributes: [ attributes: [
'id', 'id', 'title', 'description', 'time_idx_start',
'title', 'time_idx_end', 'location', 'time_idx_deadline',
'description', 'type', 'max_num', 'cur_num',
'time_idx_start',
'time_idx_end',
'location',
'time_idx_deadline',
'type',
'max_num',
'cur_num',
], ],
include: [ include: [
{ {
model: MeetingParticipant, model: MeetingParticipant,
as: 'participants', as: 'participants',
where: { user_id: userId }, required: false,
attributes: [], attributes: []
}, },
{ {
model: User, model: User,
as: 'creator', as: 'creator',
attributes: ['name'], attributes: ['name']
} }
], ],
where: { where: {
[Op.or]: [ [Op.or]: [
{ created_by: userId }, { created_by: userId },
{ '$participants.meeting_id$': { [Op.col]: 'Meeting.id' } },
{ '$participants.user_id$': userId } { '$participants.user_id$': userId }
] ]
}, },
order: [['createdAt', 'DESC']], subQuery: false,
offset order: [['created_at', 'DESC']],
limit: limit + 1,
offset,
distinct: true
}); });
const hasNext = meetings.length > limit; const hasNext = meetings.length > limit;
...@@ -427,17 +432,21 @@ class MeetingService { ...@@ -427,17 +432,21 @@ class MeetingService {
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.
Please register or to comment