feat(tkpurchase): 협력업체 포탈 3→2단계 흐름 단순화 + 작업 이력 페이지
- 체크아웃 시 work_report 자동 생성 (checkout-with-report 통합 엔드포인트) - 업무현황 입력 단계 제거, 작업자+시간만 입력하면 체크아웃 완료 - 협력업체 작업 이력 조회 페이지 신규 추가 (partner-history) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -120,4 +120,59 @@ async function deleteCheckin(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { list, myCheckins, checkIn, checkOut, update, stats, deleteCheckin };
|
||||
// 체크아웃 + 보고 통합 (협력업체 포탈 전용)
|
||||
async function checkOutWithReport(req, res) {
|
||||
try {
|
||||
const checkinId = parseInt(req.params.id);
|
||||
const checkin = await checkinModel.findById(checkinId);
|
||||
if (!checkin) return res.status(404).json({ success: false, error: '체크인 기록을 찾을 수 없습니다' });
|
||||
|
||||
// 소유권 검증: 협력업체 본인 체크인만 가능
|
||||
const companyId = req.user.partner_company_id;
|
||||
if (companyId && checkin.company_id !== companyId) {
|
||||
return res.status(403).json({ success: false, error: '권한이 없습니다' });
|
||||
}
|
||||
|
||||
// schedule에서 work_description 가져오기
|
||||
let workContent = '작업 완료';
|
||||
if (checkin.schedule_id) {
|
||||
const schedule = await scheduleModel.findById(checkin.schedule_id);
|
||||
if (schedule && schedule.work_description) {
|
||||
workContent = schedule.work_description;
|
||||
}
|
||||
}
|
||||
|
||||
const reportData = {
|
||||
reporter_id: req.user.user_id || req.user.id,
|
||||
workers: req.body.workers || [],
|
||||
work_content: workContent
|
||||
};
|
||||
|
||||
const row = await checkinModel.checkOutWithReport(checkinId, reportData);
|
||||
res.json({ success: true, data: row });
|
||||
} catch (err) {
|
||||
console.error('Checkin checkOutWithReport error:', err);
|
||||
res.status(500).json({ success: false, error: err.message });
|
||||
}
|
||||
}
|
||||
|
||||
// 작업 이력 (협력업체 포탈)
|
||||
async function myHistory(req, res) {
|
||||
try {
|
||||
const companyId = req.user.partner_company_id;
|
||||
if (!companyId) {
|
||||
return res.status(403).json({ success: false, error: '협력업체 계정이 아닙니다' });
|
||||
}
|
||||
const { date_from, date_to, page, limit } = req.query;
|
||||
const result = await checkinModel.findHistoryByCompany(companyId, {
|
||||
dateFrom: date_from, dateTo: date_to,
|
||||
page: parseInt(page) || 1, limit: parseInt(limit) || 20
|
||||
});
|
||||
res.json({ success: true, ...result });
|
||||
} catch (err) {
|
||||
console.error('Checkin myHistory error:', err);
|
||||
res.status(500).json({ success: false, error: err.message });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { list, myCheckins, checkIn, checkOut, update, stats, deleteCheckin, checkOutWithReport, myHistory };
|
||||
|
||||
Reference in New Issue
Block a user