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

[FEAT] authDoorbellGET API에 OS 정보 추가 #408

Merged
merged 2 commits into from
May 14, 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
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