feat(dashboard): backend user.js
This commit is contained in:
39
backend/src/db/index copy.js
Normal file
39
backend/src/db/index copy.js
Normal file
@@ -0,0 +1,39 @@
|
||||
// FILE: backend/src/db/index.js (ESM)
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const {
|
||||
DB_HOST = "mariadb",
|
||||
DB_PORT = "3306",
|
||||
DB_USER = "center",
|
||||
DB_PASSWORD = "Center#2025",
|
||||
DB_NAME = "dms",
|
||||
DB_CONN_LIMIT = "10",
|
||||
} = process.env;
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: DB_HOST,
|
||||
port: Number(DB_PORT),
|
||||
user: DB_USER,
|
||||
password: DB_PASSWORD,
|
||||
database: DB_NAME,
|
||||
connectionLimit: Number(DB_CONN_LIMIT),
|
||||
waitForConnections: true,
|
||||
namedPlaceholders: true,
|
||||
dateStrings: true, // คงวันที่เป็น string
|
||||
timezone: "Z", // ใช้ UTC
|
||||
});
|
||||
|
||||
/**
|
||||
* เรียก Stored Procedure แบบง่าย
|
||||
* @param {string} procName ชื่อโปรซีเยอร์ เช่น "sp_rfa_create_with_items"
|
||||
* @param {Array<any>} params ลำดับพารามิเตอร์
|
||||
* @returns {Promise<any>} rows จาก CALL
|
||||
*/
|
||||
export async function callProc(procName, params = []) {
|
||||
const placeholders = params.map(() => "?").join(",");
|
||||
const sql = `CALL ${procName}(${placeholders})`;
|
||||
const [rows] = await pool.query(sql, params);
|
||||
return rows;
|
||||
}
|
||||
|
||||
export default pool; // ใช้ sql.query(...) ได้ตามที่ routes เรียกอยู่
|
||||
@@ -1,6 +1,6 @@
|
||||
// File: backend/src/routes/users.js
|
||||
import { Router } from "express";
|
||||
import { User, Role } from "../db/index.js";
|
||||
import { User, Role } from "../db/sequelize.js";
|
||||
import { authJwt, permGuard } from "../middleware/index.js";
|
||||
import { hashPassword } from "../utils/passwords.js";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user