Skip to content

Commit

Permalink
Merge branch 'release/v1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jokj624 committed Jan 17, 2023
2 parents f9b0b7e + dd1b3e5 commit c99fb75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions functions/api/routes/auth/userDELETE.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const db = require('../../../db/db');
const { userDB } = require("../../../db");
const { getAuth } = require('firebase-admin/auth');
const { nanoid } = require("nanoid");
const { deletePushUser } = require('../../../lib/pushServerHandlers');

/**
* @route DELETE /auth/user
Expand All @@ -22,13 +23,17 @@ module.exports = async (req, res) => {

try {
client = await db.connect(req);

deleteUser = await userDB.getUser(client, userId); // DB에서 해당 유저 정보 받아 옴
} catch (error) {
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`);
console.log(error);

const slackMessage = `[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl} ${req.user ? `uid:${req.user.userId}` : 'req.user 없음'} ${JSON.stringify(error)}`;
slackAPI.sendMessageToSlack(slackMessage, slackAPI.WEB_HOOK_ERROR_MONITORING);

client.release();

return res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); // DB 관련 에러 : 500 INTERNAL SERVER ERROR
}

Expand All @@ -37,9 +42,12 @@ module.exports = async (req, res) => {
} catch (error) {
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`);
console.log(error);

const slackMessage = `[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl} ${req.user ? `uid:${req.user.userId}` : 'req.user 없음'} ${JSON.stringify(error)}`;
slackAPI.sendMessageToSlack(slackMessage, slackAPI.WEB_HOOK_ERROR_MONITORING);

client.release();

if (error.errorInfo.code === 'auth/user-not-found') {
return res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, responseMessage.NO_USER)); // Firebase Auth에 해당 유저 존재하지 않을 경우 : 404 NOT FOUND
} else {
Expand All @@ -50,6 +58,12 @@ module.exports = async (req, res) => {
try {
const randomString = `:${nanoid(10)}`;
await userDB.deleteUser(client, userId, randomString); // DB에서 해당 유저 삭제

const response = await deletePushUser(deleteUser.mongoUserId);
if (response.status != 204) {
return res.status(response.statusCode).send(util.fail(response.statusCode, response.statusText));
}

res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.DELETE_USER));
} catch (error) {
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`);
Expand Down
10 changes: 9 additions & 1 deletion functions/lib/pushServerHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ const modifyContentTitle = async (contentId, ogTitle) => {
return response;
}

module.exports = { createPushServerUser, createNotification, modifyNotificationTime, modifyFcmToken, deleteNotification, modifyContentTitle }
const deletePushUser = async (mongoUserId) => {
const url = `${baseURL}user/${mongoUserId}`;

const response = await axios.delete(url);

return response;
}

module.exports = { createPushServerUser, createNotification, modifyNotificationTime, modifyFcmToken, deleteNotification, modifyContentTitle, deletePushUser }

0 comments on commit c99fb75

Please sign in to comment.