fix(tkpurchase): 일정 목록 미표시 버그 수정 — 캐시·타임존·페이지네이션
- API에 Cache-Control: no-store 미들웨어 추가 (304 캐시 문제 해결) - toLocalDate() 유틸 추가, 전체 8개 JS의 toISOString 타임존 버그 수정 - scheduleModel.findAll에 total COUNT 추가, 컨트롤러에서 total 반환 - HTML 캐시 버스팅 ?v=2026031601 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ const scheduleModel = require('../models/scheduleModel');
|
||||
async function list(req, res) {
|
||||
try {
|
||||
const { company, company_id, date_from, date_to, status, project_id, page, limit } = req.query;
|
||||
const rows = await scheduleModel.findAll({
|
||||
const { rows, total } = await scheduleModel.findAll({
|
||||
company: company || undefined,
|
||||
company_id: company_id ? parseInt(company_id) : undefined,
|
||||
date_from,
|
||||
@@ -14,7 +14,7 @@ async function list(req, res) {
|
||||
page: page ? parseInt(page) : 1,
|
||||
limit: limit ? parseInt(limit) : 50
|
||||
});
|
||||
res.json({ success: true, data: rows });
|
||||
res.json({ success: true, data: rows, total });
|
||||
} catch (err) {
|
||||
console.error('Schedule list error:', err);
|
||||
res.status(500).json({ success: false, error: err.message });
|
||||
|
||||
@@ -37,6 +37,12 @@ app.get('/health', (req, res) => {
|
||||
res.json({ status: 'ok', service: 'tkpurchase-api', timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
// API 캐시 비활성화
|
||||
app.use('/api', (req, res, next) => {
|
||||
res.set('Cache-Control', 'no-store');
|
||||
next();
|
||||
});
|
||||
|
||||
// Routes
|
||||
app.use('/api/partners', partnerRoutes);
|
||||
app.use('/api/day-labor', dayLaborRoutes);
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
const { getPool } = require('./partnerModel');
|
||||
|
||||
function buildWhereClause({ company, company_id, date_from, date_to, status, project_id }) {
|
||||
let where = ' WHERE 1=1';
|
||||
const params = [];
|
||||
if (company) { where += ' AND pc.company_name LIKE ?'; params.push('%' + company + '%'); }
|
||||
if (company_id) { where += ' AND ps.company_id = ?'; params.push(company_id); }
|
||||
if (date_from) { where += ' AND ps.end_date >= ?'; params.push(date_from); }
|
||||
if (date_to) { where += ' AND ps.start_date <= ?'; params.push(date_to); }
|
||||
if (status) { where += ' AND ps.status = ?'; params.push(status); }
|
||||
if (project_id) { where += ' AND ps.project_id = ?'; params.push(project_id); }
|
||||
return { where, params };
|
||||
}
|
||||
|
||||
async function findAll({ company, company_id, date_from, date_to, status, project_id, page = 1, limit = 50 } = {}) {
|
||||
const db = getPool();
|
||||
let sql = `SELECT ps.*, pc.company_name, su.name AS registered_by_name,
|
||||
p.project_name, p.job_no
|
||||
FROM partner_schedules ps
|
||||
const { where, params } = buildWhereClause({ company, company_id, date_from, date_to, status, project_id });
|
||||
|
||||
const fromClause = ` FROM partner_schedules ps
|
||||
LEFT JOIN partner_companies pc ON ps.company_id = pc.id
|
||||
LEFT JOIN sso_users su ON ps.registered_by = su.user_id
|
||||
LEFT JOIN projects p ON ps.project_id = p.project_id
|
||||
WHERE 1=1`;
|
||||
const params = [];
|
||||
if (company) { sql += ' AND pc.company_name LIKE ?'; params.push('%' + company + '%'); }
|
||||
if (company_id) { sql += ' AND ps.company_id = ?'; params.push(company_id); }
|
||||
if (date_from) { sql += ' AND ps.end_date >= ?'; params.push(date_from); }
|
||||
if (date_to) { sql += ' AND ps.start_date <= ?'; params.push(date_to); }
|
||||
if (status) { sql += ' AND ps.status = ?'; params.push(status); }
|
||||
if (project_id) { sql += ' AND ps.project_id = ?'; params.push(project_id); }
|
||||
LEFT JOIN projects p ON ps.project_id = p.project_id`;
|
||||
|
||||
const [countResult] = await db.query('SELECT COUNT(*) AS cnt' + fromClause + where, params);
|
||||
|
||||
let sql = `SELECT ps.*, pc.company_name, su.name AS registered_by_name,
|
||||
p.project_name, p.job_no` + fromClause + where;
|
||||
sql += ' ORDER BY ps.start_date DESC, ps.created_at DESC';
|
||||
const offset = (page - 1) * limit;
|
||||
sql += ' LIMIT ? OFFSET ?';
|
||||
params.push(limit, offset);
|
||||
const [rows] = await db.query(sql, params);
|
||||
return rows;
|
||||
const [rows] = await db.query(sql, [...params, limit, offset]);
|
||||
return { rows, total: countResult[0].cnt };
|
||||
}
|
||||
|
||||
async function findById(id) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>계정 관리 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -133,8 +133,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-accounts.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-accounts.js?v=2026031601"></script>
|
||||
<script>initAccountsPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>일용공 신청 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -148,8 +148,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-daylabor.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-daylabor.js?v=2026031601"></script>
|
||||
<script>initDayLaborPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>대시보드 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -88,8 +88,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-dashboard.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-dashboard.js?v=2026031601"></script>
|
||||
<script>initDashboard();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>작업 이력 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -61,8 +61,8 @@
|
||||
<div id="historyPagination" class="mt-4 flex justify-center gap-2"></div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-partner-history.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-partner-history.js?v=2026031601"></script>
|
||||
<script>initPartnerHistory();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>협력업체 포털 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -81,8 +81,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-partner-portal.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-partner-portal.js?v=2026031601"></script>
|
||||
<script>initPartnerPortal();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>협력업체 관리 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -294,8 +294,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-partner.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-partner.js?v=2026031601"></script>
|
||||
<script>initPartnerPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>작업일정 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -275,8 +275,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-schedule.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-schedule.js?v=2026031601"></script>
|
||||
<script>initSchedulePage();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -104,7 +104,7 @@ function openAddAccount() {
|
||||
// Default expiration: 1 year from now
|
||||
const oneYear = new Date();
|
||||
oneYear.setFullYear(oneYear.getFullYear() + 1);
|
||||
document.getElementById('addExpiresAt').value = oneYear.toISOString().substring(0, 10);
|
||||
document.getElementById('addExpiresAt').value = toLocalDate(oneYear);
|
||||
document.getElementById('addAccountModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,12 @@ function showToast(msg, type = 'success') {
|
||||
/* ===== Escape ===== */
|
||||
function escapeHtml(str) { if (!str) return ''; const d = document.createElement('div'); d.textContent = str; return d.innerHTML; }
|
||||
|
||||
/* ===== Local Date (timezone-safe) ===== */
|
||||
function toLocalDate(d) {
|
||||
if (!(d instanceof Date) || isNaN(d)) return '';
|
||||
return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`;
|
||||
}
|
||||
|
||||
/* ===== Helpers ===== */
|
||||
function formatDate(d) { if (!d) return ''; return String(d).substring(0, 10); }
|
||||
function formatTime(d) { if (!d) return ''; return String(d).substring(11, 16); }
|
||||
|
||||
@@ -65,7 +65,7 @@ async function loadTodaySchedules() {
|
||||
} catch(e) { console.warn(e); }
|
||||
}
|
||||
|
||||
function todayStr() { return new Date().toISOString().substring(0, 10); }
|
||||
function todayStr() { return toLocalDate(new Date()); }
|
||||
|
||||
function initDashboard() {
|
||||
if (!initAuth()) return;
|
||||
|
||||
@@ -99,7 +99,7 @@ function openAddDayLabor() {
|
||||
// Default to tomorrow
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
document.getElementById('addWorkDate').value = tomorrow.toISOString().substring(0, 10);
|
||||
document.getElementById('addWorkDate').value = toLocalDate(tomorrow);
|
||||
document.getElementById('addDayLaborModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ function initDayLaborPage() {
|
||||
// Set default date range to this month
|
||||
const now = new Date();
|
||||
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateTo').value = now.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateFrom').value = toLocalDate(firstDay);
|
||||
document.getElementById('filterDateTo').value = toLocalDate(now);
|
||||
loadDayLabor();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ function initPartnerHistory() {
|
||||
const today = new Date();
|
||||
const thirtyDaysAgo = new Date(today);
|
||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
||||
document.getElementById('filterDateTo').value = today.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateFrom').value = thirtyDaysAgo.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateTo').value = toLocalDate(today);
|
||||
document.getElementById('filterDateFrom').value = toLocalDate(thirtyDaysAgo);
|
||||
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ async function renderScheduleCards() {
|
||||
const requestCardsEl = document.getElementById('requestCards');
|
||||
const workRequestFormEl = document.getElementById('workRequestForm');
|
||||
|
||||
const today = new Date().toISOString().substring(0, 10);
|
||||
const today = toLocalDate(new Date());
|
||||
|
||||
if (!portalSchedules.length) {
|
||||
container.innerHTML = '';
|
||||
|
||||
@@ -177,7 +177,7 @@ async function openAddSchedule() {
|
||||
document.getElementById('addCompanyId').value = '';
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
const tomorrowStr = tomorrow.toISOString().substring(0, 10);
|
||||
const tomorrowStr = toLocalDate(tomorrow);
|
||||
document.getElementById('addStartDate').value = tomorrowStr;
|
||||
document.getElementById('addEndDate').value = tomorrowStr;
|
||||
await loadProjects();
|
||||
@@ -446,8 +446,8 @@ function initSchedulePage() {
|
||||
const now = new Date();
|
||||
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
||||
document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateTo').value = lastDay.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateFrom').value = toLocalDate(firstDay);
|
||||
document.getElementById('filterDateTo').value = toLocalDate(lastDay);
|
||||
|
||||
// Setup autocomplete for both modals
|
||||
setupCompanyAutocomplete('addCompanySearch', 'addCompanyDropdown', 'addCompanyId');
|
||||
|
||||
@@ -140,8 +140,8 @@ function initSummaryPage() {
|
||||
// 기본 기간: 이번 달
|
||||
const now = new Date();
|
||||
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateTo').value = now.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateFrom').value = toLocalDate(firstDay);
|
||||
document.getElementById('filterDateTo').value = toLocalDate(now);
|
||||
|
||||
loadCompaniesForFilter();
|
||||
loadSchedulesForFilter();
|
||||
|
||||
@@ -404,8 +404,8 @@ function initWorkReportPage() {
|
||||
// Set default date range to this month
|
||||
const now = new Date();
|
||||
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateTo').value = now.toISOString().substring(0, 10);
|
||||
document.getElementById('filterDateFrom').value = toLocalDate(firstDay);
|
||||
document.getElementById('filterDateTo').value = toLocalDate(now);
|
||||
|
||||
loadCompaniesForFilter();
|
||||
loadReports();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>업무현황 종합 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -100,8 +100,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-workreport-summary.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-workreport-summary.js?v=2026031601"></script>
|
||||
<script>initSummaryPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title>업무현황 - TK 구매관리</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031401">
|
||||
<link rel="stylesheet" href="/static/css/tkpurchase.css?v=2026031601">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
@@ -114,8 +114,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-workreport.js?v=2026031401"></script>
|
||||
<script src="/static/js/tkpurchase-core.js?v=2026031601"></script>
|
||||
<script src="/static/js/tkpurchase-workreport.js?v=2026031601"></script>
|
||||
<script>initWorkReportPage();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user