Files
TK-FB-Project/deploy/tkfb-package/api.hyungi.net/models/toolsModel.js
Hyungi Ahn 2b1c7bfb88 feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가)
- 출근/근태 시스템 개선 (연차 조회, 근무현황)
- 작업분석 대분류 그룹화 및 마이그레이션 스크립트
- 모바일 네비게이션 UI 추가
- NAS 배포 도구 및 문서 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:41:01 +09:00

69 lines
1.8 KiB
JavaScript

const { getDb } = require('../dbPool');
// 1. 전체 도구 조회
const getAll = async () => {
const db = await getDb();
const [rows] = await db.query('SELECT id, name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note FROM Tools');
return rows;
};
// 2. 단일 도구 조회
const getById = async (id) => {
const db = await getDb();
const [rows] = await db.query('SELECT id, name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note FROM Tools WHERE id = ?', [id]);
return rows[0];
};
// 3. 도구 생성
const create = async (tool) => {
const db = await getDb();
const { name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note } = tool;
const [result] = await db.query(
`INSERT INTO Tools
(name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note]
);
return result.insertId;
};
// 4. 도구 수정
const update = async (id, tool) => {
const db = await getDb();
const { name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note } = tool;
const [result] = await db.query(
`UPDATE Tools
SET name = ?,
location = ?,
stock = ?,
status = ?,
factory_id = ?,
map_x = ?,
map_y = ?,
map_zone = ?,
map_note = ?
WHERE id = ?`,
[name, location, stock, status, factory_id, map_x, map_y, map_zone, map_note, id]
);
return result.affectedRows;
};
// 5. 도구 삭제
const remove = async (id) => {
const db = await getDb();
const [result] = await db.query('DELETE FROM Tools WHERE id = ?', [id]);
return result.affectedRows;
};
module.exports = {
getAll,
getById,
create,
update,
remove
};