diff --git a/functions/api/routes/auth/authDoorbellGET.js b/functions/api/routes/auth/authDoorbellGET.js index 264387d..99d8ba6 100644 --- a/functions/api/routes/auth/authDoorbellGET.js +++ b/functions/api/routes/auth/authDoorbellGET.js @@ -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) { @@ -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); diff --git a/functions/db/user.js b/functions/db/user.js index 113c13f..4541455 100644 --- a/functions/db/user.js +++ b/functions/db/user.js @@ -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( @@ -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( @@ -143,7 +157,7 @@ const deleteUserSoft = async(client, userId, socialId) => { [userId, now, newSocialId], ); return convertSnakeToCamel.keysToCamel(rows[0]); -} +}; module.exports = { getAllUsers, @@ -152,6 +166,7 @@ module.exports = { getUserBySocialId, addUser, updateDeviceTokenById, + updateDeviceTokenAndOsById, updateProfileById, togglePushSettingById, getUserWithDelete,