Skip to content

Commit

Permalink
Merge pull request #408 from TeamSparker/feature/#404
Browse files Browse the repository at this point in the history
[FEAT] authDoorbellGET API에 OS 정보 추가
  • Loading branch information
youngkwon02 authored May 14, 2022
2 parents 7b2a781 + 7b1e6e2 commit 4e8d79d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions functions/api/routes/auth/authDoorbellGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { userDB } = require('../../../db');
*/

module.exports = async (req, res) => {
const { socialId, fcmToken } = req.query;
const { socialId, fcmToken, os } = req.query;

// @error 1. socialId 또는 fcmToken 누락
if (!socialId || !fcmToken) {
Expand All @@ -36,7 +36,13 @@ module.exports = async (req, res) => {

let data = jwtHandlers.sign(user);
data.isNew = false;
await userDB.updateDeviceTokenById(client, user.userId, fcmToken);

if (!os) {
await userDB.updateDeviceTokenById(client, user.userId, fcmToken);
} else {
await userDB.updateDeviceTokenAndOsById(client, user.userId, fcmToken, os);
}

return res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.ALREADY_SIGNED_UP, data));
} catch (error) {
console.log(error);
Expand Down
21 changes: 18 additions & 3 deletions functions/db/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ const updateDeviceTokenById = async (client, userId, fcmToken) => {
return convertSnakeToCamel.keysToCamel(rows[0]);
};

const updateDeviceTokenAndOsById = async (client, userId, fcmToken, os) => {
const now = dayjs().add(9, 'hour');
const { rows } = await client.query(
`
UPDATE spark.user
SET device_token = $2, os = $3, updated_at = $4
WHERE user_id = $1
RETURNING *
`,
[userId, fcmToken, os, now],
);
return convertSnakeToCamel.keysToCamel(rows[0]);
};

const updateProfileById = async (client, userId, nickname, profileImg) => {
const now = dayjs().add(9, 'hour');
const { rows } = await client.query(
Expand Down Expand Up @@ -129,8 +143,8 @@ const emptyDeviceTokenById = async (client, userId) => {
return convertSnakeToCamel.keysToCamel(rows[0]);
};

const deleteUserSoft = async(client, userId, socialId) => {
const now = dayjs().add(9,'hour');
const deleteUserSoft = async (client, userId, socialId) => {
const now = dayjs().add(9, 'hour');
const nowToString = now.format('YYYYMMDDHHmmssSSS');
const newSocialId = `${socialId}-out-${nowToString}`;
const { rows } = await client.query(
Expand All @@ -143,7 +157,7 @@ const deleteUserSoft = async(client, userId, socialId) => {
[userId, now, newSocialId],
);
return convertSnakeToCamel.keysToCamel(rows[0]);
}
};

module.exports = {
getAllUsers,
Expand All @@ -152,6 +166,7 @@ module.exports = {
getUserBySocialId,
addUser,
updateDeviceTokenById,
updateDeviceTokenAndOsById,
updateProfileById,
togglePushSettingById,
getUserWithDelete,
Expand Down

0 comments on commit 4e8d79d

Please sign in to comment.