Skip to content

Commit 5ef2dcc

Browse files
authored
[FIX] 홈화면 관련 요청사항 수정
2 parents 8757c72 + 4de2027 commit 5ef2dcc

4 files changed

Lines changed: 25 additions & 43 deletions

File tree

src/DTO/work_log_dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*/
44
export interface TodayScheduleResponseDto {
55
workLogId: string;
6+
storeId: string | null; // 알바 공고 기반 근무의 근무지 ID (수동 등록 시 null)
67
status: 'scheduled' | 'working' | 'done' | 'settled' | 'absent';
78
statusLabel: string; // "예정", "근무 중", "근무 완료", "정산 완료", "결근"
89
workplace: string; // "CU 홍대 점"
10+
workplaceName: string | null; // 근무지 별칭 (사용자 지정 이름)
911
startTime: string; // "14:00"
1012
endTime: string; // "18:00"
1113
workHours: number; // 4

src/repository/work_log_repository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ class WorkLogRepository {
112112
alba_posting: {
113113
hourly_rate: number | null;
114114
store: {
115+
store_id: Uint8Array;
115116
store_name: string | null;
116117
};
117118
} | null;
118119
user_alba_schedule: {
119120
address: string | null;
120121
category: string | null;
122+
workplace_name: string | null;
121123
} | null;
122124
}[]
123125
> {
@@ -141,6 +143,7 @@ class WorkLogRepository {
141143
hourly_rate: true,
142144
store: {
143145
select: {
146+
store_id: true,
144147
store_name: true,
145148
},
146149
},
@@ -150,6 +153,7 @@ class WorkLogRepository {
150153
select: {
151154
address: true,
152155
category: true,
156+
workplace_name: true,
153157
},
154158
},
155159
},
Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,28 @@
1-
import WorkRepository from '../repository/work_repository';
1+
import WorkLogService from './work_log_service';
2+
import { uuidToBin } from '../util/uuid';
23
import { TodayWorkSummaryResponse } from '../DTO/alba_schedule_dto';
34

45
/**
5-
* // 오늘의 근무 요약 정보 조회
6-
* // 오늘 예정된 근무 개수, 총 근무 시간, 예상 수입 계산
7-
* @param userId // 사용자 UUID 문자열
8-
* @returns // 오늘의 근무 요약 응답 DTO
6+
* 오늘의 근무 요약 정보 조회
7+
* user_work_log 기반으로 집계하여 오늘의 근무 리스트 API와 동일한 데이터 소스 사용
8+
* @param userId - 사용자 UUID 문자열
9+
* @returns 오늘의 근무 요약 응답 DTO
910
*/
11+
export const GET_TODAY_WORK_SUMMARY = async (userId: string): Promise<TodayWorkSummaryResponse> => {
12+
const userIdBuffer = uuidToBin(userId);
13+
const { schedules } = await WorkLogService.getTodaySchedules(userIdBuffer);
1014

11-
export const GET_TODAY_WORK_SUMMARY = async ( userId: string,): Promise<TodayWorkSummaryResponse> => {
12-
// == 오늘 요일 구하기 = > (MON, TUE, WED, THU, FRI, SAT, SUN) ==
13-
const todayDayOfWeek = GET_TODAY_DAY_OF_WEEK();
14-
15-
// == Repository에서 오늘의 근무 스케줄 조회 ==
16-
const works = await WorkRepository.findTodayWorks(userId, todayDayOfWeek);
17-
18-
// == 총 근무 시간 및 예상 수입 계산 ==
1915
let totalWorkMinutes = 0;
2016
let expectedIncome = 0;
2117

22-
for (const work of works) {
23-
// 근무 시간 계산 (분 단위)
24-
const minutes = CALCULATE_WORK_MINUTES(work.start_time, work.end_time);
25-
26-
totalWorkMinutes += minutes;
27-
// 예상 수입 = (근무 시간 / 60) * 시급, 소수점 버림
28-
expectedIncome += Math.floor((minutes / 60) * work.hourly_wage);
18+
for (const s of schedules) {
19+
totalWorkMinutes += Math.round(s.workHours * 60);
20+
expectedIncome += s.totalWage;
2921
}
3022

31-
// == 응답 DTO 반환 ==
3223
return {
33-
workCount: works.length,
24+
workCount: schedules.length,
3425
totalWorkMinutes,
3526
expectedIncome,
3627
};
3728
};
38-
39-
// ===== Helper Functions =====
40-
41-
/**
42-
* 오늘 요일을 DB enum 형식으로 반환
43-
* @returns 요일 문자열 (MON, TUE, WED, THU, FRI, SAT, SUN)
44-
*/
45-
const GET_TODAY_DAY_OF_WEEK = (): string => {
46-
const dayMap = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
47-
const today = new Date();
48-
return dayMap[today.getDay()];
49-
};
50-
51-
/**
52-
* 두 시간 사이의 근무 시간을 분 단위로 계산
53-
* @param start - 근무 시작 시간
54-
* @param end - 근무 종료 시간
55-
* @returns 근무 시간 (분)
56-
*/
57-
const CALCULATE_WORK_MINUTES = (start: Date, end: Date): number =>
58-
Math.max(0, (end.getTime() - start.getTime()) / 60000);

src/service/work_log_service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ class WorkLogService {
6161
);
6262

6363
// alba_posting이 있으면 사용, 없으면 schedule에서 fallback
64+
let storeId: string | null = null;
6465
let workplace = '';
6566
let hourlyWage = 0;
6667

6768
if (log.alba_posting) {
69+
storeId = bufferToUuid(log.alba_posting.store.store_id);
6870
workplace = log.alba_posting.store.store_name || '';
6971
hourlyWage = log.alba_posting.hourly_rate || 0;
7072
} else if (log.user_alba_schedule_id) {
@@ -78,18 +80,22 @@ class WorkLogService {
7880

7981
let address = '';
8082
let category = '';
83+
let workplaceName: string | null = null;
8184

8285
if (log.user_alba_schedule) {
8386
address = log.user_alba_schedule.address || '';
8487
category = log.user_alba_schedule.category || '';
88+
workplaceName = log.user_alba_schedule.workplace_name || null;
8589
}
8690

8791
const totalWage = Math.round(hourlyWage * workHours);
8892
const status = log.status || 'scheduled';
8993

9094
return {
9195
workLogId: bufferToUuid(log.user_work_log_id),
96+
storeId,
9297
status,
98+
workplaceName,
9399
statusLabel: STATUS_LABELS[status] || '알 수 없음',
94100
workplace,
95101
startTime,

0 commit comments

Comments
 (0)