This commit is contained in:
parent
f74de8256e
commit
13c8fd0ee7
57
apps/user.js
57
apps/user.js
|
@ -1,4 +1,4 @@
|
||||||
import express, { query } from 'express';
|
import express from 'express';
|
||||||
import { createDatabaseConnection } from '../db/database.js'; // db 연결 파일을 import
|
import { createDatabaseConnection } from '../db/database.js'; // db 연결 파일을 import
|
||||||
import { dbConfig } from '../private/config.js';
|
import { dbConfig } from '../private/config.js';
|
||||||
|
|
||||||
|
@ -6,60 +6,53 @@ export const HandleUser = async (req, res) => {
|
||||||
const actionPath = req.params[0]; // 'userRead/sns'와 같은 나머지 경로를 잡아냄
|
const actionPath = req.params[0]; // 'userRead/sns'와 같은 나머지 경로를 잡아냄
|
||||||
const actionParts = actionPath.split('/'); // 슬래시로 나누어 배열로 변환
|
const actionParts = actionPath.split('/'); // 슬래시로 나누어 배열로 변환
|
||||||
const action = actionParts[0]; // 첫 번째 부분 ('userRead')
|
const action = actionParts[0]; // 첫 번째 부분 ('userRead')
|
||||||
// const { sns_id = '' };
|
|
||||||
|
|
||||||
if (action === 'userRead') { // && actionParts[1] === 'sns') {
|
if (action === 'userRead') {
|
||||||
res.send(`Action: ${action}, ${actionParts}`);
|
// res.send(`Action: ${action}, ${actionParts}`); // 이 줄은 테스트용이므로 실제 응답 전에 사용 금지
|
||||||
|
|
||||||
|
let query;
|
||||||
|
let queryParams;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const connection = await createDatabaseConnection(dbConfig);
|
const connection = await createDatabaseConnection(dbConfig);
|
||||||
|
|
||||||
if (actionParts[1] === 'sns') {
|
if (actionParts[1] === 'sns') {
|
||||||
// sns_id = req.query;
|
|
||||||
const { sns_id } = req.query; // 쿼리 파라미터에서 sns_id를 받아옴
|
const { sns_id } = req.query; // 쿼리 파라미터에서 sns_id를 받아옴
|
||||||
if (!sns_id) {
|
if (!sns_id) {
|
||||||
|
await connection.end();
|
||||||
return res.status(400).json({ error: 'sns_id is required' });
|
return res.status(400).json({ error: 'sns_id is required' });
|
||||||
}
|
}
|
||||||
const query = 'SELECT * FROM user_info WHERE sns_id = ?';
|
query = 'SELECT * FROM user_info WHERE sns_id = ?';
|
||||||
const [rows] = await connection.query(query, [sns_id]);
|
queryParams = [sns_id];
|
||||||
}
|
}
|
||||||
|
else if (actionParts[1] === 'app') {
|
||||||
else if(actionParts[1] === 'app') {
|
|
||||||
const { app_id } = req.query;
|
const { app_id } = req.query;
|
||||||
if (!app_id) {
|
if (!app_id) {
|
||||||
|
await connection.end();
|
||||||
return res.status(400).json({ error: 'app_id is required' });
|
return res.status(400).json({ error: 'app_id is required' });
|
||||||
}
|
}
|
||||||
const query = 'SELECT * FROM user_info WHERE app_id = ?';
|
query = 'SELECT * FROM user_info WHERE app_id = ?';
|
||||||
const [rows] = await connection.query(query, [app_id]);
|
queryParams = [app_id];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await connection.end();
|
||||||
|
return res.status(400).json({ error: 'Invalid sub-action' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [rows] = await connection.query(query, queryParams);
|
||||||
|
|
||||||
await connection.end();
|
await connection.end();
|
||||||
|
|
||||||
if (rows.length === 0) {
|
if (rows.length === 0) {
|
||||||
return res.status(404).json({ message: 'User not found' });
|
return res.status(404).json({ message: 'User not found' });
|
||||||
}
|
}
|
||||||
return res.json(rows[0]);
|
|
||||||
|
|
||||||
// try {
|
return res.json(rows[0]); // 사용자의 첫 번째 정보를 반환
|
||||||
// const connection = await createDatabaseConnection(dbConfig);
|
|
||||||
|
|
||||||
// const query = 'SELECT * FROM user_info WHERE sns_id = ?';
|
|
||||||
// const [rows] = await connection.query(query, [sns_id]);
|
|
||||||
|
|
||||||
// await connection.end();
|
|
||||||
|
|
||||||
// if (rows.length === 0) {
|
|
||||||
// return res.status(404).json({ message: 'User not found' });
|
|
||||||
// }
|
|
||||||
// return res.json(rows[0]); // 사용자의 첫 번째 정보를 반환
|
|
||||||
// } catch (err) {
|
|
||||||
// return res.status(500).json({ error: err.message });
|
|
||||||
// }
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({ error: err.message });
|
return res.status(500).json({ error: err.message });
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return res.status(400).send('Invalid action');
|
||||||
}
|
}
|
||||||
else {
|
};
|
||||||
res.status(400).send('Invalid action');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 추가적인 'action' 처리도 여기에 추가 가능
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user