Skip to content

Commit

Permalink
✨ [FEAT]: user 삭제 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
eunji8784 committed Dec 24, 2021
1 parent 2bf5de1 commit 79d99a4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions 5st-seminar/functions/api/routes/user/userDELETE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const functions = require("firebase-functions");
const util = require("../../../lib/util");
const statusCode = require("../../../constants/statusCode");
const responseMessage = require("../../../constants/responseMessage");
const db = require("../../../db/db");
const { userDB } = require("../../../db");

module.exports = async (req, res) => {
const { userId } = req.params;

if (!userId)
return res
.status(statusCode.BAD_REQUEST)
.send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));

let client;

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

const deletedUser = await userDB.deleteUser(client, userId);

res
.status(statusCode.OK)
.send(
util.success(
statusCode.OK,
responseMessage.DELETE_ONE_USER_SUCCESS,
deletedUser
)
);
} catch (error) {
functions.logger.error(
`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`,
`[CONTENT] ${error}`
);
console.log(error);

res
.status(statusCode.INTERNAL_SERVER_ERROR)
.send(
util.fail(
statusCode.INTERNAL_SERVER_ERROR,
responseMessage.INTERNAL_SERVER_ERROR
)
);
} finally {
client.release();
}
};

0 comments on commit 79d99a4

Please sign in to comment.