Skip to content

Commit 588192c

Browse files
committed
fix(work_log): alba_posting 없는 수동 일정의 workplace, hourlyWage fallback 조회
→ repository 타입 변경 반영 + fallback 로직
1 parent 5c43788 commit 588192c

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

src/service/work_log_service.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import WorkLogRepository from '../repository/work_log_repository';
2+
import prisma from '../config/prisma';
23
import {
34
TodayScheduleResponseDto,
45
TodayWorkListResponseDto,
@@ -35,6 +36,22 @@ class WorkLogService {
3536
// Repository에서 오늘 날짜의 work_log 가져오기
3637
const workLogs = await WorkLogRepository.findWorkLogsByDate(userId, today);
3738

39+
// alba_posting이 없는 work_log의 schedule 정보를 일괄 조회
40+
const scheduleIds = workLogs
41+
.filter((log) => !log.alba_posting && log.user_alba_schedule_id)
42+
.map((log) => log.user_alba_schedule_id as Uint8Array<ArrayBuffer>);
43+
44+
const scheduleMap = new Map<string, { workplace: string | null; hourly_wage: number | null }>();
45+
if (scheduleIds.length > 0) {
46+
const schedules = await prisma.user_alba_schedule.findMany({
47+
where: { user_alba_schedule_id: { in: scheduleIds } },
48+
select: { user_alba_schedule_id: true, workplace: true, hourly_wage: true },
49+
});
50+
for (const s of schedules) {
51+
scheduleMap.set(Buffer.from(s.user_alba_schedule_id).toString('hex'), s);
52+
}
53+
}
54+
3855
// DTO 형식으로 변환
3956
const scheduleDtos: TodayScheduleResponseDto[] = workLogs.map((log) => {
4057
const { startTime, endTime, workHours } = this.parseWorkLogTime(
@@ -43,15 +60,30 @@ class WorkLogService {
4360
log.work_minutes,
4461
);
4562

46-
const hourlyWage = log.alba_posting.hourly_rate || 0;
63+
// alba_posting이 있으면 사용, 없으면 schedule에서 fallback
64+
let workplace = '';
65+
let hourlyWage = 0;
66+
67+
if (log.alba_posting) {
68+
workplace = log.alba_posting.store.store_name || '';
69+
hourlyWage = log.alba_posting.hourly_rate || 0;
70+
} else if (log.user_alba_schedule_id) {
71+
const key = Buffer.from(log.user_alba_schedule_id).toString('hex');
72+
const schedule = scheduleMap.get(key);
73+
if (schedule) {
74+
workplace = schedule.workplace || '';
75+
hourlyWage = schedule.hourly_wage || 0;
76+
}
77+
}
78+
4779
const totalWage = Math.round(hourlyWage * workHours);
4880
const status = log.status || 'scheduled';
4981

5082
return {
5183
workLogId: bufferToUuid(log.user_work_log_id),
5284
status,
5385
statusLabel: STATUS_LABELS[status] || '알 수 없음',
54-
workplace: log.alba_posting.store.store_name || '',
86+
workplace,
5587
startTime,
5688
endTime,
5789
workHours,

0 commit comments

Comments
 (0)