From 174129f22a7e3bfa0e53ceb824a8406eb85cd35b Mon Sep 17 00:00:00 2001 From: EungGu Yun Date: Wed, 11 Dec 2019 19:31:37 +0900 Subject: [PATCH] Add user withdraw --- src/backend/handler.js | 22 ++++++++++++++++++++++ src/backend/handlers/item.js | 1 - src/backend/handlers/user.js | 25 ++++++++++++++++++++++++- src/backend/responses/template.js | 5 ++++- src/backend/responses/user.js | 20 +++++++++++++++++++- src/backend/serverless.yml | 12 ++++++++++++ src/backend/utils/resource.js | 5 ++--- 7 files changed, 83 insertions(+), 7 deletions(-) diff --git a/src/backend/handler.js b/src/backend/handler.js index 2731741..881dea8 100644 --- a/src/backend/handler.js +++ b/src/backend/handler.js @@ -84,6 +84,28 @@ module.exports.userOpenprofile = async (event) => { } }; +module.exports.userWithdrawWarning = async (event) => { + if (await checkAuth(event) != null) { + const response = await userHandler.withdrawWarning(event); + console.log(response); + return response; + } else { + console.log("Auth fail"); + return getAuthFailResponse(); + } +}; + +module.exports.userWithdraw = async (event) => { + if (await checkAuth(event) != null) { + const response = await userHandler.withdraw(event); + console.log(response); + return response; + } else { + console.log("Auth fail"); + return getAuthFailResponse(); + } +}; + module.exports.itemRegistration = async (event) => { if (event.source === "serverless-plugin-warmup") { console.log("WarmUP"); diff --git a/src/backend/handlers/item.js b/src/backend/handlers/item.js index 3657267..c9abb88 100644 --- a/src/backend/handlers/item.js +++ b/src/backend/handlers/item.js @@ -132,7 +132,6 @@ const deleteWarning = async (event) => { return responseTemplate.itemDeleteWarning(itemId, item_image); }; -// Todo const deleteOk = async (event) => { const extras = parser.getExtras(event); const itemId = extras["itemId"]; diff --git a/src/backend/handlers/user.js b/src/backend/handlers/user.js index c1dbf8c..f825a6f 100644 --- a/src/backend/handlers/user.js +++ b/src/backend/handlers/user.js @@ -69,9 +69,32 @@ const openprofile = async (event) => { } }; +const withdrawWarning = async (event) => { + return responseTemplate.userWithdrawWarning(); +}; + +const withdraw = async (event) => { + const userId = parser.getUserId(event); + const extras = parser.getExtras(event); + const action = extras["action"]; + + if (action == "ok") { + const result = await database.deleteUser(userId); + if (result.success == true) { + return responseTemplate.userWithdrawOk(); + } else { + return responseTemplate.processFail("회원 탈퇴 실패", "회원 탈퇴에 실패하였습니다."); + } + } else { + return responseTemplate.userWithdrawCancel(); + } +}; + module.exports = { registration, authentication, information, - openprofile + openprofile, + withdrawWarning, + withdraw }; diff --git a/src/backend/responses/template.js b/src/backend/responses/template.js index 63aebcd..3f92a4e 100644 --- a/src/backend/responses/template.js +++ b/src/backend/responses/template.js @@ -23,5 +23,8 @@ module.exports = { itemDeleteWarning: itemResponse.itemDeleteWarning, itemDeleteOk: itemResponse.itemDeleteOk, itemDeleteCancel: itemResponse.itemDeleteCancel, - userOpenprofileSuccess: userResponse.userOpenprofileSuccess + userOpenprofileSuccess: userResponse.userOpenprofileSuccess, + userWithdrawWarning: userResponse.userWithdrawWarning, + userWithdrawOk: userResponse.userWithdrawOk, + userWithdrawCancel: userResponse.userWithdrawCancel }; diff --git a/src/backend/responses/user.js b/src/backend/responses/user.js index 33b5e09..2c41914 100644 --- a/src/backend/responses/user.js +++ b/src/backend/responses/user.js @@ -48,7 +48,7 @@ module.exports.userInformation = (nickname, school_name, school_mail, openprofil const infoOpenProfileList = builder.getListItem(openprofile, "오픈프로필 주소"); const infoReliabilityScoreList = builder.getListItem(reliability_score, "신뢰도"); const infoOpenProfileButton = builder.getButton("오픈프로필", "webLink", openprofile); - const infoWithdrawButton = builder.getButton("회원 탈퇴", "block", "회원 탈퇴", resource.userWithdrawBlockId); + const infoWithdrawButton = builder.getButton("회원 탈퇴", "block", "회원 탈퇴", resource.userWithdrawWarningBlockId); const infoCard = builder.getListCard(infoTitle, "", [infoNicknameList, infoSchoolNameList, infoSchoolMailList, infoOpenProfileList, infoReliabilityScoreList], [infoOpenProfileButton, infoWithdrawButton]); @@ -69,3 +69,21 @@ module.exports.userOpenprofileSuccess = (openprofile) => { const listCard = builder.getListCard("오픈프로필 등록 성공", "", [listItem]); return builder.buildResponse([listCard]); }; + +module.exports.userWithdrawWarning = () => { + const okButton = builder.getButton("확인", "block", "확인", resource.userWithdrawBlockId, {action: "ok"}); + const cancelButton = builder.getButton("취소", "block", "취소", resource.userWithdrawBlockId, {action: "cancel"}); + const basicCard = builder.getBasicCard("정말 회원을 탈퇴하시겠습니까?", "", "", [okButton, cancelButton]); + return builder.buildResponse([basicCard], false); +}; + +module.exports.userWithdrawOk = () => { + const resultThumbnail = builder.getThumbnail(resource.itemRegistrationSuccessThumbnailUrl); + const basicCard = builder.getBasicCard("회원에서 탈퇴했습니다.", "", resultThumbnail); + return builder.buildResponse([basicCard]); +}; + +module.exports.userWithdrawCancel = () => { + const textCard = builder.getSimpleText("회원 탈퇴를 취소했습니다."); + return builder.buildResponse([textCard]); +}; diff --git a/src/backend/serverless.yml b/src/backend/serverless.yml index 9ce22e2..6d4a9ad 100644 --- a/src/backend/serverless.yml +++ b/src/backend/serverless.yml @@ -97,6 +97,18 @@ functions: - http: path: user/openprofile method: post + userWithdrawWarning: + handler: handler.userWithdrawWarning + events: + - http: + path: user/withdraw/warning + method: post + userWithdraw: + handler: handler.userWithdraw + events: + - http: + path: user/withdraw + method: post test: handler: handler.test events: diff --git a/src/backend/utils/resource.js b/src/backend/utils/resource.js index 5051fb4..5ba04de 100644 --- a/src/backend/utils/resource.js +++ b/src/backend/utils/resource.js @@ -30,8 +30,7 @@ module.exports = { itemDetailBlockId: "5decfa26ffa74800014b098e", itemDeleteWarningBlockId: "5df085bdffa74800014b1f92", itemDeleteBlockId: "5df0a89292690d0001fc015b", - itemBuyBlockId: "5decfa26ffa74800014b098e", // Temp itemReportBlockId: "5decfa26ffa74800014b098e", // Temp - userWithdrawBlockId: "5de3d56d8192ac0001d65d18", // Temp - itemSellerContractVerifyBlockId: "5de3d56d8192ac0001d65d18", // Temp + userWithdrawWarningBlockId: "5df0be478192ac00017876ac", + userWithdrawBlockId: "5df0be598192ac00017876ae", };