-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from innovationacademy-kr/yoyoo
Yoyoo
- Loading branch information
Showing
20 changed files
with
337 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const pool = require('../config/database'); | ||
const { sendResponse, isNumeric } = require('../utils/util'); | ||
const query = require('../db/query'); | ||
|
||
// 고장 사물함 리스트 조회 | ||
const getInactivatedCabinet = async (_req, res) => { | ||
const connection = await pool.getConnection(); | ||
try { | ||
const cabinetList = await query.getInactivatedCabinetList(connection); | ||
return sendResponse(res, cabinetList, 200); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
const patchActivation = async (req, res) => { | ||
const { cabinetIdx, activation, reason } = req.body; | ||
if ( | ||
!cabinetIdx && | ||
!activation && | ||
!isNumeric(activation) && | ||
!isNumeric(cabinetIdx) | ||
) { | ||
return sendResponse(res, {}, 400); | ||
} | ||
|
||
const connection = await pool.getConnection(); | ||
try { | ||
connection.beginTransaction(); | ||
|
||
await query.modifyCabinetActivation(connection, cabinetIdx, activation); | ||
if (activation === 0) | ||
await query.addDisablelog(connection, cabinetIdx, reason); | ||
else await query.modifyDisablelog(connection, cabinetIdx); | ||
connection.commit(); | ||
return sendResponse(res, 'ok', 200); | ||
} catch (err) { | ||
connection.rollback(); | ||
console.log(err); | ||
return sendResponse(res, err, 500); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getInactivatedCabinet, | ||
patchActivation, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require('dotenv').config({ path: '../.env' }); | ||
const jwt = require('jsonwebtoken'); | ||
const { sendResponse } = require('../utils/util'); | ||
const { getJwtSecret } = require('../config/config'); | ||
|
||
const postLogin = (req, res) => { | ||
const { id, password } = req.body; | ||
if (!id || !password) { | ||
return sendResponse(res, {}, 400, 'Input error'); | ||
} | ||
if (id !== process.env.ADMIN_ID || password !== process.env.ADMIN_PASSWORD) { | ||
return sendResponse(res, {}, 403, 'Authentication fail'); | ||
} | ||
const payload = {}; | ||
const accessToken = jwt.sign(payload, getJwtSecret(), { expiresIn: '24h' }); | ||
|
||
return sendResponse(res, { accessToken }, 200, 'Authentication success'); | ||
}; | ||
|
||
module.exports = { | ||
postLogin, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { sendResponse } = require('../utils/util'); | ||
const { getCabinetInfoByFloor } = require('../db/query'); | ||
const pool = require('../config/database'); | ||
|
||
// 층별 사물함 현황(sum) | ||
const getCabinetCountFloor = async (_req, res) => { | ||
const connection = await pool.getConnection(); | ||
try { | ||
const cabientInfoByFloor = await getCabinetInfoByFloor(connection); | ||
return sendResponse(res, cabientInfoByFloor, 200); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getCabinetCountFloor, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { getLentUserInfo, getLentOverdue } = require('../db/query'); | ||
const { sendResponse } = require('../utils/util'); | ||
const pool = require('../config/database'); | ||
|
||
const getLentInfo = async (_req, res) => { | ||
const connection = await pool.getConnection(); | ||
try { | ||
const lentInfo = await getLentUserInfo(connection); | ||
return sendResponse(res, lentInfo, 200); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
const getLentOverdueInfo = async (_req, res) => { | ||
const connection = await pool.getConnection(); | ||
try { | ||
const overdueInfo = await getLentOverdue(connection); | ||
return sendResponse(res, overdueInfo, 200); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getLentInfo, | ||
getLentOverdueInfo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const query = require('../db/query'); | ||
const { sendResponse, isNumeric } = require('../utils/util'); | ||
const pool = require('../config/database'); | ||
|
||
// 특정 사물함의 정보 ( 대여중이라면: + 유저 + 렌트 정보) 가져옴 | ||
const getReturn = async (req, res) => { | ||
const { cabinetIdx } = req.query; | ||
|
||
if (!cabinetIdx && !isNumeric(cabinetIdx)) { | ||
return sendResponse(res, {}, 400); | ||
} | ||
|
||
const connection = await pool.getConnection(); | ||
try { | ||
const cabinetInfo = await query.getCabinet(connection, cabinetIdx); | ||
if (!cabinetInfo) { | ||
return sendResponse(res, {}, 400); | ||
} | ||
return sendResponse(res, cabinetInfo, 200); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
// 특정 사물함 반납 처리 | ||
const patchReturn = async (req, res) => { | ||
const { cabinetIdx } = req.query; | ||
if (!cabinetIdx && !isNumeric(cabinetIdx)) { | ||
return sendResponse(res, {}, 400); | ||
} | ||
|
||
const connection = await pool.getConnection(); | ||
try { | ||
await connection.beginTransaction(); | ||
|
||
// 해당 사물함의 user, lent 정보 가져옴 | ||
const userLentInfo = await query.getUserLent(connection, cabinetIdx); | ||
if (!userLentInfo) { | ||
return sendResponse(res, {}, 400); | ||
} | ||
|
||
await Promise.all([ | ||
query.deleteLent(connection, userLentInfo), // lent 테이블에서 해당 사물함의 대여 정보 삭제 | ||
query.addLentLog(connection, userLentInfo), // lent_log에 반납되는 사물함 정보 추가 | ||
]); | ||
|
||
await connection.commit(); | ||
return sendResponse(res, 'ok', 200); | ||
} catch (err) { | ||
await connection.rollback(); | ||
return undefined; | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getReturn, | ||
patchReturn, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const query = require('../db/query'); | ||
const { isNumeric, sendResponse } = require('../utils/util'); | ||
const pool = require('../config/database'); | ||
// intra_id, cabinetNum 검색 기능 | ||
const getSearch = async (req, res) => { | ||
const { intraId, cabinetNum, floor } = req.query; | ||
|
||
const connection = await pool.getConnection(); | ||
try { | ||
let resultFromLent; | ||
let resultFromLentLog; | ||
|
||
if (intraId) { | ||
[resultFromLent, resultFromLentLog] = await Promise.all([ | ||
query.getLentByIntraId(connection, intraId), | ||
query.getLentLogByIntraId(connection, intraId), | ||
]); | ||
} else if ( | ||
cabinetNum && | ||
floor && | ||
isNumeric(cabinetNum) && | ||
isNumeric(floor) | ||
) { | ||
[resultFromLent, resultFromLentLog] = await Promise.all([ | ||
query.getLentByCabinetNum(connection, cabinetNum, floor), | ||
query.getLentLogByCabinetNum(connection, cabinetNum, floor), | ||
]); | ||
} else { | ||
return sendResponse(res, {}, 400); | ||
} | ||
|
||
const result = { resultFromLent, resultFromLentLog }; | ||
return sendResponse(res, result, 200); | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
module.exports = { | ||
getSearch, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE IF NOT EXISTS `cabinet` ( | ||
`cabinet_id` int(11) NOT NULL AUTO_INCREMENT, | ||
`cabinet_num` int(11) NOT NULL, | ||
`location` varchar(30) COLLATE utf8_bin NOT NULL, | ||
`floor` int(11) NOT NULL, | ||
`section` varchar(30) NOT NULL, | ||
`activation` tinyint(4) NOT NULL, | ||
PRIMARY KEY (`cabinet_id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=latin1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const fs = require('fs'); | ||
const readline = require('readline'); | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
const pool = require('../config/database'); | ||
|
||
const disabledLogQuery = fs | ||
.readFileSync('./disabled-log.sql') | ||
.toString('utf-8'); | ||
const userQuery = fs.readFileSync('./user.sql').toString('utf-8'); | ||
const cabinetQuery = fs.readFileSync('./cabinet.sql').toString('utf-8'); | ||
|
||
const init = async () => { | ||
try { | ||
await Promise.all([ | ||
pool.query(disabledLogQuery), | ||
pool.query(userQuery), | ||
pool.query(cabinetQuery), | ||
]); | ||
console.log(' ✅ User Table'); | ||
console.log(' ✅ Cabinet Table'); | ||
console.log(' ✅ Disable Log Table'); | ||
} catch (error) { | ||
console.log(`❌ ${error}`); | ||
} finally { | ||
pool.end(); | ||
} | ||
}; | ||
|
||
console.log( | ||
'\n 해당 명령어는 한 번만 사용하시면 됩니다.\n\n\x1b[35m `user` `cabinet` `disable`\x1b[0m 테이블을 만듭니다.\n 테이블이 존재하는 경우엔 만들지 않습니다.\n\n 만드시겠습니까? [y/n] (EOF는 yes 처리됩니다.)' | ||
); | ||
|
||
rl.on('line', (line) => { | ||
if (line === 'n') { | ||
process.exit(); | ||
} else if (line === 'y') { | ||
rl.close(); | ||
} else { | ||
console.log('[y/n]으로 입력해주세요'); | ||
} | ||
}); | ||
rl.on('SIGINT', () => { | ||
process.exit(); | ||
}); | ||
rl.on('SIGQUIT', () => { | ||
process.exit(); | ||
}); | ||
rl.on('close', () => { | ||
init(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE IF NOT EXISTS `disable` ( | ||
`disable_id` INT AUTO_INCREMENT PRIMARY KEY, | ||
`disable_cabinet_id` INT NOT NULL, | ||
`disable_time` TIMESTAMP DEFAULT current_timestamp, | ||
`fix_time` TIMESTAMP, | ||
`status` TINYINT DEFAULT 1, | ||
`note` TEXT | ||
) ENGINE=innoDB DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE IF NOT EXISTS `user` ( | ||
`user_id` int(11) NOT NULL, | ||
`intra_id` varchar(30) NOT NULL, | ||
`auth` tinyint(4) NOT NULL, | ||
`email` varchar(128) DEFAULT NULL, | ||
`phone` varchar(128) DEFAULT NULL, | ||
PRIMARY KEY (`user_id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"compilerOptions": {}, | ||
"exclude": ["dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.