Replaced `SELECT *` statements across multiple data models with explicit column lists to improve query performance, reduce data transfer, and increase code clarity. This is part of the Phase 2 refactoring plan. - Refactored queries in the following models: - projectModel - toolsModel - attendanceModel - dailyIssueReportModel - issueTypeModel - workReportModel - userModel - dailyWorkReportModel fix(api): Add missing volume mounts to docker-compose Modified docker-compose.yml to mount the `config`, `middlewares`, `utils`, and `services` directories into the API container. This fixes a `MODULE_NOT_FOUND` error that caused the container to crash on startup. feat(db): Add migration for missing project columns Created a new database migration to add `is_active`, `project_status`, and `completed_date` columns to the `projects` table, resolving an inconsistency between the model code and the schema. docs: Add deployment notes Added a new markdown file to document the testing (macOS, Docker Desktop) and production (Synology NAS, Container Manager) environments.
120 lines
3.3 KiB
JavaScript
120 lines
3.3 KiB
JavaScript
const { getDb } = require('../dbPool');
|
|
|
|
const create = async (project, callback) => {
|
|
try {
|
|
const db = await getDb();
|
|
const {
|
|
job_no, project_name,
|
|
contract_date, due_date,
|
|
delivery_method, site, pm,
|
|
is_active = true,
|
|
project_status = 'active',
|
|
completed_date = null
|
|
} = project;
|
|
|
|
const [result] = await db.query(
|
|
`INSERT INTO projects
|
|
(job_no, project_name, contract_date, due_date, delivery_method, site, pm, is_active, project_status, completed_date)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
[job_no, project_name, contract_date, due_date, delivery_method, site, pm, is_active, project_status, completed_date]
|
|
);
|
|
|
|
callback(null, result.insertId);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
};
|
|
|
|
const getAll = async (callback) => {
|
|
try {
|
|
const db = await getDb();
|
|
const [rows] = await db.query(
|
|
`SELECT project_id, job_no, project_name, contract_date, due_date, delivery_method, site, pm, is_active, project_status, completed_date, created_at, updated_at FROM projects ORDER BY project_id DESC`
|
|
);
|
|
callback(null, rows);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
};
|
|
|
|
// 활성 프로젝트만 조회 (작업보고서용)
|
|
const getActiveProjects = async (callback) => {
|
|
try {
|
|
const db = await getDb();
|
|
const [rows] = await db.query(
|
|
`SELECT project_id, job_no, project_name, contract_date, due_date, delivery_method, site, pm, is_active, project_status, completed_date, created_at, updated_at FROM projects
|
|
WHERE is_active = TRUE
|
|
ORDER BY project_name ASC`
|
|
);
|
|
callback(null, rows);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
};
|
|
|
|
const getById = async (project_id, callback) => {
|
|
try {
|
|
const db = await getDb();
|
|
const [rows] = await db.query(
|
|
`SELECT project_id, job_no, project_name, contract_date, due_date, delivery_method, site, pm, is_active, project_status, completed_date, created_at, updated_at FROM projects WHERE project_id = ?`,
|
|
[project_id]
|
|
);
|
|
callback(null, rows[0]);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
};
|
|
|
|
const update = async (project, callback) => {
|
|
try {
|
|
const db = await getDb();
|
|
const {
|
|
project_id, job_no, project_name,
|
|
contract_date, due_date,
|
|
delivery_method, site, pm,
|
|
is_active, project_status, completed_date
|
|
} = project;
|
|
|
|
const [result] = await db.query(
|
|
`UPDATE projects
|
|
SET job_no = ?,
|
|
project_name = ?,
|
|
contract_date = ?,
|
|
due_date = ?,
|
|
delivery_method= ?,
|
|
site = ?,
|
|
pm = ?,
|
|
is_active = ?,
|
|
project_status = ?,
|
|
completed_date = ?
|
|
WHERE project_id = ?`,
|
|
[job_no, project_name, contract_date, due_date, delivery_method, site, pm, is_active, project_status, completed_date, project_id]
|
|
);
|
|
|
|
callback(null, result.affectedRows);
|
|
} catch (err) {
|
|
callback(new Error(err.message || String(err)));
|
|
}
|
|
};
|
|
|
|
const remove = async (project_id, callback) => {
|
|
try {
|
|
const db = await getDb();
|
|
const [result] = await db.query(
|
|
`DELETE FROM projects WHERE project_id = ?`,
|
|
[project_id]
|
|
);
|
|
callback(null, result.affectedRows);
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
create,
|
|
getAll,
|
|
getActiveProjects,
|
|
getById,
|
|
update,
|
|
remove
|
|
}; |