Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#86/detailedSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
zheedong committed Sep 26, 2020
2 parents fc08a56 + 6788516 commit 3385db0
Show file tree
Hide file tree
Showing 13 changed files with 1,427 additions and 769 deletions.
7 changes: 7 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pull_request_rules:
- name: Automatic merge 📥 on approval ✔
conditions:
- '#approved-reviews-by>=2'
actions:
merge:
method: merge
368 changes: 278 additions & 90 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
},
"homepage": "https://github.com/BeLeap/KUICS_backend#readme",
"devDependencies": {
"eslint": "^7.8.1",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"eslint": "^7.9.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"mocha": "^8.1.3",
"nodemon": "^2.0.4",
"prettier": "^2.1.1"
"prettier": "^2.1.2"
},
"dependencies": {
"@hapi/joi": "^17.1.1",
Expand All @@ -35,21 +37,21 @@
"cross-env": "^7.0.2",
"crypto": "^1.0.1",
"dotenv": "^8.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"express": "^4.17.1",
"express-swagger-generator": "^1.1.17",
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"morgan": "^1.10.0",
"mysql": "^2.18.1",
"mysql2": "^2.1.0",
"mysql2": "^2.2.5",
"passport": "^0.4.1",
"passport-google-oauth20": "^2.0.0",
"pg": "^8.3.3",
"pm2": "^4.4.1",
"sequelize": "^6.3.5",
"swagger-jsdoc": "^4.0.0",
"swagger-jsdoc": "^4.2.0",
"swagger-ui-express": "^4.1.4",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.4.2",
Expand Down
128 changes: 107 additions & 21 deletions src/api/admin/admin.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ const {
userIdScheme,
} = require('../../lib/schemes');

const isAdmin = async (email) => {
const { isAdmin } = require('../../lib/validations');

const {
postFunction,
reviseFunction,
deleteFunction,
} = require('../../lib/postingFunctions');

const isAdmin_temp = async (email) => {
const admin = await users.findOne({
where: { email, state: 0, level: 999 },
});
return admin;
};
}; // TODO: ../../lib/validations의 isAdmin과 통합
// TODO: const admin = await isAdmin(req.user.emails[0].value);

/**
* 유저 정보를 읽어옴
Expand All @@ -25,8 +34,9 @@ const isAdmin = async (email) => {
*/
const getUser = async (req, res, next) => {
try {
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

// 관리자 API라 관리자, 탈퇴자 모두 반환하도록 함.
const userList = await users.findAll();
Expand Down Expand Up @@ -54,8 +64,9 @@ const getUser = async (req, res, next) => {
*/
const postUser = async (req, res, next) => {
try {
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

const { error, value } = userScheme.validate(req.body);
if (error) throw new Error('INVALID_PARAMETERS');
Expand Down Expand Up @@ -93,8 +104,9 @@ const postUser = async (req, res, next) => {
*/
const updateUserPermission = async (req, res, next) => {
try {
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

const { error, value } = permScheme.validate(req.body);
if (error) throw new Error('INVALID_PARAMETERS');
Expand Down Expand Up @@ -123,8 +135,9 @@ const updateUserPermission = async (req, res, next) => {
*/
const deleteUser = async (req, res, next) => {
try {
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

const { error, value } = userIdScheme.validate(req.params.userId);
if (error) throw new Error('INVALID_PARAMETERS');
Expand Down Expand Up @@ -158,7 +171,7 @@ const deleteUser = async (req, res, next) => {
* 소개글 작성
* @typedef Intro
* @property {string} title.required - 제목
* @property {string} content.required - 내용
* @property {{Array<string>}} content.required - 내용
*/

/**
Expand All @@ -172,8 +185,9 @@ const deleteUser = async (req, res, next) => {
*/
const postIntro = async (req, res, next) => {
try {
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

const { error, value } = introScheme.validate(req.body);
if (error) throw new Error('INVALID_PARAMETERS');
Expand All @@ -200,8 +214,9 @@ const postIntro = async (req, res, next) => {
*/
const updateIntro = async (req, res, next) => {
try {
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

const { error, value } = updateIntroScheme.validate({
...req.body,
Expand Down Expand Up @@ -235,8 +250,9 @@ const updateIntro = async (req, res, next) => {
const deleteIntro = async (req, res, next) => {
try {
// TODO: 어드민 체크
const checkAdmin = await isAdmin(req.user.emails[0].value);
if (!checkAdmin) throw new Error('NOT_ADMIN');
const admin = await isAdmin_temp(req.user.emails[0].value);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NOT_ADMIN');

const { error, value } = introIdScheme.validate(req.params.introId);
if (error) throw new Error('INVALID_PARAMETERS');
Expand All @@ -253,17 +269,87 @@ const deleteIntro = async (req, res, next) => {
}
};

const postNotice = async (req, res, next) => {};
const putEditNotice = async (req, res, next) => {};
const deleteNotice = async (req, res, next) => {};
/**
* @typedef boardScheme
* @property {string} title.required
* @property {{Array<string>}} body.required
* @property {number} level.required
*/

/**
* 공지글 작성하기
* @route POST /api/admin/notice
* @group Admin
* @param {boardScheme.model} boardScheme.body.required - 작성할 글 정보
* @returns {Object} 200 - 빈 객체
* @returns {Error} INVALID_PARAMETERS - invalid Parameters
* @returns {Error} NO_AUTH - unauthorized
*/
const postNotice = async (req, res, next) => {
try {
/* admin check */
const admin = await isAdmin(req.query.userId);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NO_AUTH');

postFunction(req, res, next, 'notice');
} catch (err) {
next(err);
}
};

/**
* boardId에 해당하는 공지글 수정하기
* @route PUT /api/admin/notice/{boardId}
* @group Admin
* @param {number} boardId.path.required - 글 번호
* @param {boardScheme.model} boardScheme.body.required - 작성할 글 정보
* @returns {Object} 200 - 빈 객체
* @returns {Error} INVALID_PARAMETERS - invalid Parameters
* @returns {Error} NO_AUTH - unauthorized
*/
const reviseNotice = async (req, res, next) => {
try {
/* admin check */
const admin = await isAdmin(req.query.userId);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NO_AUTH');

reviseFunction(req, res, next, 'notice');
} catch (err) {
next(err);
}
};

/**
* boardId에 해당하는 글 삭제하기
* @route DELETE /api/admin/notice/{boardId}
* @group Admin
* @param {number} boardId.path.required - 글 번호
* @returns {Object} 200 - 빈 객체
* @returns {Error} INVALID_PARAMETERS - invalid Parameters
* @returns {Error} NO_AUTH - unauthorized
*/
const deleteNotice = async (req, res, next) => {
try {
/* admin check */
const admin = await isAdmin(req.query.userId);
/* const admin = await isAdmin(req.user.emails[0].value); */
if (!admin) throw new Error('NO_AUTH');

deleteFunction(req, res, next, 'notice');
} catch (err) {
next(err);
}
};

module.exports = {
getUser,
postUser,
updateUserPermission,
deleteUser,
postNotice,
putEditNotice,
reviseNotice,
deleteNotice,
postIntro,
updateIntro,
Expand Down
8 changes: 4 additions & 4 deletions src/api/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
updateUserPermission,
deleteUser,
postNotice,
putEditNotice,
reviseNotice,
deleteNotice,
postIntro,
updateIntro,
Expand All @@ -20,9 +20,9 @@ router.post('/user', isAuthenticated, postUser); // 사용자 추가
router.put('/user/permission', isAuthenticated, updateUserPermission); // 사용자 등급 변경
router.delete('/user/:userId', isAuthenticated, deleteUser); // 사용자 삭제

router.post('/notice', isAuthenticated, postNotice); // 공지 작성
router.put('/notice/:notice_id', isAuthenticated, putEditNotice); // 공지 수정
router.delete('/notice/:notice_id', isAuthenticated, deleteNotice); // 공지 삭제
router.post('/notice', postNotice); // 공지 작성
router.put('/notice/:boardId', reviseNotice); // 공지 수정
router.delete('/notice/:boardId', deleteNotice); // 공지 삭제

router.post('/intro', isAuthenticated, postIntro);
router.put('/intro/:introId', isAuthenticated, updateIntro);
Expand Down
Loading

0 comments on commit 3385db0

Please sign in to comment.