Skip to content

Commit

Permalink
Merge pull request #213 from Neogasogaeseo/choi_fix/#212
Browse files Browse the repository at this point in the history
Choi fix/#212
  • Loading branch information
realwhyjay authored Oct 3, 2022
2 parents f8c7fb0 + 7701c3b commit 5c2c878
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion functions/api/routes/report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const router = express.Router();
const { checkUser } = require('../../../middlewares/auth');
const uploadImage = require('../../../middlewares/uploadImage');

router.get('/:reportKind', require('./reportCategoryGET'));
router.get('/', require('./reportCategoryGET'));
router.post('/', checkUser, uploadImage('report'), require('./reportPOST'));

module.exports = router;
25 changes: 1 addition & 24 deletions functions/api/routes/report/reportCategoryGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,12 @@ const slackAPI = require('../../../lib/slackAPI');
const { reportDB } = require('../../../db');

module.exports = async (req, res) => {
const { reportKind } = req.params;
if (!reportKind) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}

let client;

function checkReportKind(reportKind) {
let kindId = 0;
switch (reportKind) {
case 'customer':
kindId = 1;
break;
case 'team':
kindId = 2;
break;
default:
}
return kindId;
}
try {
client = await db.connect(req);

const reportKindId = checkReportKind(reportKind);
// ^_^// 가져온 kind로 해당 카테고리 조회
if (reportKindId === 0) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NO_REPORT_CATEGORY));
}
const reportCategory = await reportDB.getReportCategory(client, reportKindId);
const reportCategory = await reportDB.getReportCategory(client);

return res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.READ_REPORT_CATEGORY_SUCCESS, { reportCategory }));
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions functions/api/routes/team/teamMemberEditPOST.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const db = require('../../../db/db');
const slackAPI = require('../../../lib/slackAPI');
const { memberDB } = require('../../../db');


const extractValues = (arr, key) => {
if (!Array.isArray(arr)) return [arr[key] || null];
return [...new Set(arr.map((o) => o[key]).filter(Boolean))];
Expand All @@ -15,6 +16,7 @@ module.exports = async (req, res) => {
const user = req.user;
const { teamId, userIdList } = req.body;


if (!user || !teamId || userIdList === 0) return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));

let client;
Expand Down
6 changes: 6 additions & 0 deletions functions/api/routes/user/keywordCreatePOST.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ module.exports = async (req, res) => {
}

let newKeyword;
// ^_^// 이미 존재하는 키워드인지 검색한뒤

const alreadyKeyword = await keywordDB.checkKeyword(client, name, userId);
// console.log('alreadyKeyword', alreadyKeyword);

if (alreadyKeyword) {
// ^_^// 이미 존재한다면 해당 키워드의 count를 + 해준다

newKeyword = await keywordDB.addKeyword(client, alreadyKeyword.id);
// console.log('oldNewKeyword : ', newKeyword);
} else {
// ^_^// 존재하지 않는 키워드라면 키워드를 생성해준다

const colorId = Math.floor(Math.random() * 4) + 1;
newKeyword = await keywordDB.addNewKeyword(client, name, userId, colorId);
// console.log('realNewKeyword :', newKeyword);
Expand Down
7 changes: 4 additions & 3 deletions functions/db/memberDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const addMember = async (client, teamId, userIdList) => {
}

const valuesInsertQuery = userIdList.map((x) => `(${teamId}, ${x})`).join(', ');

const { rows: resultRows } = await client.query(
`
INSERT INTO member
Expand All @@ -107,13 +108,13 @@ const checkMemberHost = async (client, userId, teamId) => {
FROM "member" m
WHERE m.user_id = $1
AND m.team_id = $2
AND is_host = true
AND is_deleted = false
AND m.is_host = true
AND m.is_deleted = false
`,

[userId, teamId],
);

console.log(rows);
return convertSnakeToCamel.keysToCamel(rows[0]);
};

Expand Down
3 changes: 1 addition & 2 deletions functions/db/reportDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ const _ = require('lodash');
const { ClientBase } = require('pg');
const convertSnakeToCamel = require('../lib/convertSnakeToCamel');

const getReportCategory = async (client, reportKindId) => {
const getReportCategory = async (client) => {
const { rows } = await client.query(
`
SELECT c.id, c.name
FROM "report_category" c
JOIN "report_kind" k
ON c.report_kind_id = k.id
WHERE k.id = ${reportKindId}
`,
);
console.log(rows);
Expand Down
17 changes: 13 additions & 4 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"express": "^4.17.1",
"firebase": "^9.6.2",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
"firebase-functions": "^3.24.1",
"fs": "0.0.1-security",
"helmet": "^4.6.0",
"hpp": "^0.2.3",
Expand Down

0 comments on commit 5c2c878

Please sign in to comment.