Skip to content

Commit

Permalink
Merge pull request #211 from Neogasogaeseo/joo_feat/#210
Browse files Browse the repository at this point in the history
[fix] QA
  • Loading branch information
ozzing authored Sep 14, 2022
2 parents 3815274 + 10752ae commit f8c7fb0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions functions/api/routes/auth/authLoginPOST.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async (req, res) => {
let kakao_profile;
let authUser;
let client;
if (!authenticationCode) {
if (!provider || !authenticationCode) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}
try {
Expand All @@ -34,7 +34,7 @@ module.exports = async (req, res) => {
});
} catch (error) {
console.log(error);
return res.status(statusCode.NOT_FOUND).json(util.fail(statusCode.NOT_FOUND, responseMessage.WRONG_AUTH));
return res.status(statusCode.BAD_REQUEST).json(util.fail(statusCode.BAD_REQUEST, responseMessage.WRONG_AUTH));
}

try {
Expand All @@ -45,7 +45,7 @@ module.exports = async (req, res) => {
},
});
} catch (error) {
return res.status(statusCode.NOT_FOUND).json(util.fail(statusCode.NOT_FOUND, responseMessage.WRONG_TOKEN));
return res.status(statusCode.BAD_REQUEST).json(util.fail(statusCode.BAD_REQUEST, responseMessage.WRONG_TOKEN));
}

try {
Expand Down
8 changes: 5 additions & 3 deletions functions/api/routes/form/formMyAllGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ module.exports = async (req, res) => {
client = await db.connect(req);

//^_^// formId 답변 유무, 최신순 정렬
const myFormIdRecentList = await answerDB.getRecentFormIdListByUserId(client, userId);
const myFormIdRecentList = await answerDB.getFormIdListByUserId(client, userId);
myFormIdRecentList.sort(function (a, b) {
if (b.cnt === '0') return -1;
else if (b.createdAt < a.createdAt) return -1;
});

if (myFormIdRecentList.length === 0) {
return res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.NO_MY_FORM_CONTENT));
}
const idUnique = myFormIdRecentList.filter((form, index, arr) => {
return arr.findIndex((item) => item.formId === form.formId) === index;
return arr.findIndex((item) => item.id === form.id) === index;
});
let idList = extractValues(idUnique, 'formId');

let idList = extractValues(idUnique, 'id');
const count = idList.length;

//^_^// form id로 form, answer 정보 가져오기
Expand Down
8 changes: 5 additions & 3 deletions functions/api/routes/form/formMyGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ module.exports = async (req, res) => {
client = await db.connect(req);

//^_^// formId 답변 유무, 최신순 정렬
const myFormIdRecentList = await answerDB.getRecentFormIdListByUserId(client, userId);
const myFormIdRecentList = await answerDB.getFormIdListByUserId(client, userId);
myFormIdRecentList.sort(function (a, b) {
if (b.cnt === '0') return -1;
else if (b.createdAt < a.createdAt) return -1;
});

if (myFormIdRecentList.length === 0) {
return res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.NO_MY_FORM_CONTENT));
}
const idUnique = myFormIdRecentList.filter((form, index, arr) => {
return arr.findIndex((item) => item.formId === form.formId) === index;
return arr.findIndex((item) => item.id === form.id) === index;
});
let idList = extractValues(idUnique, 'formId');

let idList = extractValues(idUnique, 'id');
const count = idList.length;
if (idList.length > 2) idList = idList.slice(0, 2);

Expand Down
9 changes: 7 additions & 2 deletions functions/api/routes/team/teamIssueGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const db = require('../../../db/db');
const { issueDB } = require('../../../db');
const resizeImage = require('../../../lib/resizeImage');
const slackAPI = require('../../../lib/slackAPI');
const { result } = require('lodash');

const extractValues = (arr, key) => {
if (!Array.isArray(arr)) return [arr[key] || null];
Expand Down Expand Up @@ -37,6 +38,7 @@ module.exports = async (req, res) => {
for (const issue of myIssue) {
issue.createdAt = dayjs(issue.createdAt).format('YYYY-MM-DD');
}
console.log(myIssue);

const myTeam = await issueDB.getTeamByIssueIdList(client, idList);
myTeam.forEach((item) => (item.image = resizeImage(item.image)));
Expand All @@ -63,9 +65,12 @@ module.exports = async (req, res) => {
myTeam.forEach((team) => map.set(team.issueId, { ...map.get(team.issueId), team }));
const resultList = Array.from(map.values());

let i = 0;
resultList.forEach((item) => {
item.feedback.forEach((o) => delete o.issueId);
delete item.team.issueId;
if (item.feedback) {
item.feedback.forEach((o) => delete o.issueId);
delete item.team.issueId;
}
});

res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.READ_MY_ISSUE_SUCCESS, resultList));
Expand Down
8 changes: 4 additions & 4 deletions functions/db/answerDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ const getAnswerByFormIdAndUserIdForFormDetailTopKeyword = async (client, formId,
return convertSnakeToCamel.keysToCamel(rows);
};

const getRecentFormIdListByUserId = async (client, userId) => {
const getFormIdListByUserId = async (client, userId) => {
const { rows } = await client.query(
`
SELECT l.form_id, l.created_at, COUNT(a.id) as cnt
SELECT l.form_id as id, l.created_at, COUNT(a.id) as cnt
FROM "link_user_form" l
LEFT JOIN "answer" a
ON l.id = a.link_user_form_id
WHERE l.user_id = $1
AND l.is_deleted = false
GROUP BY l.form_id, l.created_at
ORDER BY created_at DESC
`,
[userId],
);
Expand Down Expand Up @@ -249,7 +249,7 @@ module.exports = {
addAnswer,
getAnswerByFormIdListAndUserID,
getAnswerUserIdByAnswerId,
getRecentFormIdListByUserId,
getFormIdListByUserId,
getAnswerByFormIdList,
getAnswerByFormIdAndUserId,
getAnswerCountByFormIdAndUserId,
Expand Down
4 changes: 3 additions & 1 deletion functions/db/formDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@ const getFormDetail = async (client, formId, userId) => {
const getFormByFormIdList = async (client, formIdList, userId) => {
const { rows } = await client.query(
`
SELECT f.id, f.title, f.subtitle, f.dark_icon_image, f.created_at
SELECT f.id, f.title, f.subtitle, f.dark_icon_image, l.created_at
FROM "form" f
JOIN "link_user_form" l
ON l.form_id = f.id
WHERE f.is_deleted = false
AND l.is_deleted = false
AND l.user_id = $1
AND f.id in (${formIdList.join(',')})
ORDER BY l.created_at DESC
`,
[userId],
);
Expand Down

0 comments on commit f8c7fb0

Please sign in to comment.