Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] SignUP ReqBody 수정 #91

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions functions/api/routes/auth/authSignUpPOST.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const slackAPI = require('../../../middlewares/slackAPI');
*/

module.exports = async (req, res) => {
const { socialId, nickname } = req.body;
const { socialId, nickname, fcmToken } = req.body;
const profileImg = req.imageUrls;
console.log(socialId, nickname, profileImg);
// @error 1. socialId/nickname이 전달되지 않음
if (!socialId || !nickname) {
if (!socialId || !nickname || !fcmToken) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}
// @error 3. 닉네임 10자 초과
Expand All @@ -39,9 +39,10 @@ module.exports = async (req, res) => {
}
let user;
if (profileImg.length) {
user = await userDB.addUser(client, socialId, nickname, profileImg[0]);
user = await userDB.addUser(client, socialId, nickname, profileImg[0], fcmToken);
} else {
user = await userDB.addUser(client, socialId, nickname, null);
const defaultProfile = 'https://firebasestorage.googleapis.com/v0/b/we-sopt-spark.appspot.com/o/common%2Fprofile_empty.png?alt=media&token=194cf154-6a1b-4ffe-9e51-6f07b3c45490';
user = await userDB.addUser(client, socialId, nickname, defaultProfile, fcmToken);
}
const { accesstoken } = jwtHandlers.sign(user);
console.log(user);
Expand Down
8 changes: 4 additions & 4 deletions functions/db/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ const getUserBySocialId = async (client, socialId) => {
return convertSnakeToCamel.keysToCamel(rows[0]);
};

const addUser = async (client, socialId, nickname, profileImg) => {
const addUser = async (client, socialId, nickname, profileImg, fcmToken) => {
const { rows } = await client.query(
`
INSERT INTO spark.user
(social_id, nickname, profile_img)
(social_id, nickname, profile_img, device_token)
VALUES
($1, $2, $3)
($1, $2, $3, $4)
RETURNING user_id, nickname, profile_img
`,
[socialId, nickname, profileImg],
[socialId, nickname, profileImg, fcmToken],
);
return convertSnakeToCamel.keysToCamel(rows[0]);
};
Expand Down