[✨] user.js 생성 및 userRead 추가
All checks were successful
JJ_Back/pipeline/head This commit looks good
All checks were successful
JJ_Back/pipeline/head This commit looks good
This commit is contained in:
parent
83c60a7456
commit
f74de8256e
|
@ -3,11 +3,10 @@ import { createDatabaseConnection } from '../db/database.js'; // db 연결 파
|
|||
import { dbConfig } from '../private/config.js';
|
||||
|
||||
import { HandlePush } from './push.js';
|
||||
import { HandleUser } from './user.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/push', HandlePush);
|
||||
|
||||
router.get('/version', async (req, res) => {
|
||||
const {os_type} = req.query;
|
||||
|
||||
|
@ -32,6 +31,11 @@ router.get('/version', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
router.get('/push', HandlePush);
|
||||
|
||||
router.get('/user/*', HandleUser);
|
||||
|
||||
export default router;
|
||||
|
||||
|
||||
|
|
65
apps/user.js
Normal file
65
apps/user.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
import express, { query } from 'express';
|
||||
import { createDatabaseConnection } from '../db/database.js'; // db 연결 파일을 import
|
||||
import { dbConfig } from '../private/config.js';
|
||||
|
||||
export const HandleUser = async (req, res) => {
|
||||
const actionPath = req.params[0]; // 'userRead/sns'와 같은 나머지 경로를 잡아냄
|
||||
const actionParts = actionPath.split('/'); // 슬래시로 나누어 배열로 변환
|
||||
const action = actionParts[0]; // 첫 번째 부분 ('userRead')
|
||||
// const { sns_id = '' };
|
||||
|
||||
if (action === 'userRead') { // && actionParts[1] === 'sns') {
|
||||
res.send(`Action: ${action}, ${actionParts}`);
|
||||
try {
|
||||
const connection = await createDatabaseConnection(dbConfig);
|
||||
|
||||
if (actionParts[1] === 'sns') {
|
||||
// sns_id = req.query;
|
||||
const { sns_id } = req.query; // 쿼리 파라미터에서 sns_id를 받아옴
|
||||
if (!sns_id) {
|
||||
return res.status(400).json({ error: 'sns_id is required' });
|
||||
}
|
||||
const query = 'SELECT * FROM user_info WHERE sns_id = ?';
|
||||
const [rows] = await connection.query(query, [sns_id]);
|
||||
}
|
||||
|
||||
else if(actionParts[1] === 'app') {
|
||||
const { app_id } = req.query;
|
||||
if (!app_id) {
|
||||
return res.status(400).json({ error: 'app_id is required' });
|
||||
}
|
||||
const query = 'SELECT * FROM user_info WHERE app_id = ?';
|
||||
const [rows] = await connection.query(query, [app_id]);
|
||||
}
|
||||
|
||||
await connection.end();
|
||||
if (rows.length === 0) {
|
||||
return res.status(404).json({ message: 'User not found' });
|
||||
}
|
||||
return res.json(rows[0]);
|
||||
|
||||
// try {
|
||||
// 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) {
|
||||
return res.status(500).json({ error: err.message });
|
||||
}
|
||||
}
|
||||
else {
|
||||
res.status(400).send('Invalid action');
|
||||
}
|
||||
|
||||
// 추가적인 'action' 처리도 여기에 추가 가능
|
||||
};
|
Loading…
Reference in New Issue
Block a user