Commit efe07467 authored by KangMin An's avatar KangMin An
Browse files

Update : DB & Server Info Message 정리

parent 4ca7dadf
import db from "../db";
const DB_QUERY_ERROR_MSG = "DB Query Error.";
const DB_CONNECTION_ERROR_MSG = "DB Connection Error.";
const SERVER_ERROR_MSG = "The server encountered an error.";
const QUERY_SUCCESS_MSG = "Query Success.";
const STATUS_OK_CODE = 200;
const STATUS_SERVER_ERROR_CODE = 500;
import { getPoolConnection as db, dbMSG } from "../db";
import { serverMSG, statusCode } from "../serverinfo";
export const getDo = async (req, res) => {
const query = "SELECT CODE, DONAME FROM LOCDO";
db((connErr, connection) => {
if (connErr) {
console.log(DB_CONNECTION_ERROR_MSG);
res.status(STATUS_SERVER_ERROR_CODE).json({ error: SERVER_ERROR_MSG });
console.log(dbMSG.connection_err);
res.status(statusCode.err).json({ error: serverMSG.server_err });
} else {
connection.query(query, (queryErr, result) => {
if (queryErr) {
console.log(DB_QUERY_ERROR_MSG);
res
.status(STATUS_SERVER_ERROR_CODE)
.json({ error: SERVER_ERROR_MSG });
console.log(dbMSG.query_err);
res.status(statusCode.err).json({ error: serverMSG.server_err });
} else {
console.log(QUERY_SUCCESS_MSG);
res.status(STATUS_OK_CODE).json({ info: result });
console.log(dbMSG.query_success);
res.status(statusCode.ok).json({ info: result });
}
});
......@@ -42,18 +33,16 @@ export const getSGG = (req, res) => {
db((connErr, connection) => {
if (connErr) {
console.log(DB_CONNECTION_ERROR_MSG);
res.status(STATUS_SERVER_ERROR_CODE).json({ error: SERVER_ERROR_MSG });
console.log(dbMSG.connection_err);
res.status(statusCode.err).json({ error: serverMSG.server_err });
} else {
connection.query(query, (queryErr, result) => {
if (queryErr) {
console.log(DB_QUERY_ERROR_MSG);
res
.status(STATUS_SERVER_ERROR_CODE)
.json({ error: SERVER_ERROR_MSG });
console.log(dbMSG.query_err);
res.status(statusCode.err).json({ error: serverMSG.server_err });
} else {
console.log(QUERY_SUCCESS_MSG);
res.status(STATUS_OK_CODE).json({ info: result });
console.log(dbMSG.query_success);
res.status(statusCode.ok).json({ info: result });
}
});
......@@ -71,18 +60,16 @@ export const getEMD = (req, res) => {
db((connErr, connection) => {
if (connErr) {
console.log(DB_CONNECTION_ERROR_MSG);
res.status(STATUS_SERVER_ERROR_CODE).json({ error: SERVER_ERROR_MSG });
console.log(dbMSG.connection_err);
res.status(statusCode.err).json({ error: serverMSG.server_err });
} else {
connection.query(query, (queryErr, result) => {
if (queryErr) {
console.log(DB_QUERY_ERROR_MSG);
res
.status(STATUS_SERVER_ERROR_CODE)
.json({ error: SERVER_ERROR_MSG });
console.log(dbMSG.query_err);
res.status(statusCode.err).json({ error: serverMSG.server_err });
} else {
console.log(QUERY_SUCCESS_MSG);
res.status(STATUS_OK_CODE).json({ info: result });
console.log(dbMSG.query_success);
res.status(statusCode.ok).json({ info: result });
}
});
......
......@@ -16,7 +16,7 @@ const db_config = {
const pool = mysql.createPool(db_config);
// Pool을 이용시, Connection을 생성 후 반환하여 사용
const connection = (callback) => {
export const getPoolConnection = (callback) => {
console.log("db_connection()");
pool.getConnection(async (err, connection) => {
console.log("db_connection_poolConnection()");
......@@ -24,4 +24,8 @@ const connection = (callback) => {
});
};
export default connection;
export const dbMSG = {
connection_err: "DB Connection Error.",
query_err: "DB Query Error.",
query_success: "Query Success",
};
const SERVER_ERROR_MSG = "The server encountered an error.";
const STATUS_OK_CODE = 200;
const STATUS_ERROR_CODE = 500;
export const serverMSG = {
server_err: SERVER_ERROR_MSG,
};
export const statusCode = {
ok: STATUS_OK_CODE,
err: STATUS_ERROR_CODE,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment