Files
TK-FB-Project/api.hyungi.net/models/userModel.js
Hyungi Ahn bc5df77595 refactor(db): Replace SELECT * with explicit columns in models
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.
2025-12-19 10:33:29 +09:00

75 lines
2.2 KiB
JavaScript

const { getDb } = require('../dbPool');
// 사용자 조회
const findByUsername = async (username) => {
try {
const db = await getDb();
const [rows] = await db.query(
'SELECT user_id, username, password, name, email, role, access_level, worker_id, is_active, last_login_at, password_changed_at, failed_login_attempts, locked_until, created_at, updated_at FROM users WHERE username = ?', [username]
);
return rows[0];
} catch (err) {
console.error('DB 오류 - 사용자 조회 실패:', err);
throw err;
}
};
/**
* 로그인 실패 횟수를 1 증가시킵니다.
* @param {number} userId - 사용자 ID
*/
const incrementFailedLoginAttempts = async (userId) => {
try {
const db = await getDb();
await db.execute(
'UPDATE users SET failed_login_attempts = failed_login_attempts + 1 WHERE user_id = ?',
[userId]
);
} catch (err) {
console.error('DB 오류 - 로그인 실패 횟수 증가 실패:', err);
throw err;
}
};
/**
* 특정 사용자의 계정을 잠급니다.
* @param {number} userId - 사용자 ID
*/
const lockUserAccount = async (userId) => {
try {
const db = await getDb();
await db.execute(
'UPDATE users SET locked_until = DATE_ADD(NOW(), INTERVAL 15 MINUTE) WHERE user_id = ?',
[userId]
);
} catch (err) {
console.error('DB 오류 - 계정 잠금 실패:', err);
throw err;
}
};
/**
* 로그인 성공 시, 마지막 로그인 시간을 업데이트하고 실패 횟수와 잠금 상태를 초기화합니다.
* @param {number} userId - 사용자 ID
*/
const resetLoginAttempts = async (userId) => {
try {
const db = await getDb();
await db.execute(
'UPDATE users SET last_login_at = NOW(), failed_login_attempts = 0, locked_until = NULL WHERE user_id = ?',
[userId]
);
} catch (err) {
console.error('DB 오류 - 로그인 상태 초기화 실패:', err);
throw err;
}
};
// 명확한 내보내기
module.exports = {
findByUsername,
incrementFailedLoginAttempts,
lockUserAccount,
resetLoginAttempts
};