Commit 41352d1f authored by KangMin An's avatar KangMin An
Browse files

Update: Toggle using aircon status.

parent aa804067
...@@ -127,10 +127,7 @@ export const postLogin = async (req, res) => { ...@@ -127,10 +127,7 @@ export const postLogin = async (req, res) => {
// 로그아웃 요청 처리 // 로그아웃 요청 처리
export const getLogout = (req, res) => { export const getLogout = (req, res) => {
res.clearCookie("acs_token").redirect("/api"); res.clearCookie("acs_token");
// .redirect(
// `${envs.client.protocol}://${envs.client.host}:${envs.client.port}`
// );
}; };
// 메일로 보낸 토큰의 유효성 검사 및 access 토큰 발행 처리 // 메일로 보낸 토큰의 유효성 검사 및 access 토큰 발행 처리
...@@ -229,7 +226,7 @@ export const getUserInfo = async (req, res) => { ...@@ -229,7 +226,7 @@ export const getUserInfo = async (req, res) => {
export const postEditProfile = async (req, res) => { export const postEditProfile = async (req, res) => {
const { const {
cookies: { acs_token }, cookies: { acs_token },
body: { nick_name, loc_code, using_aircon }, body: { nick_name, loc_code },
} = req; } = req;
try { try {
...@@ -243,15 +240,11 @@ export const postEditProfile = async (req, res) => { ...@@ -243,15 +240,11 @@ export const postEditProfile = async (req, res) => {
let new_nick_name = nick_name ? nick_name : user.nick_name; let new_nick_name = nick_name ? nick_name : user.nick_name;
let new_loc_code = loc_code ? Number(loc_code) : Number(user.loc_code); let new_loc_code = loc_code ? Number(loc_code) : Number(user.loc_code);
let new_using_aircon = using_aircon
? using_aircon === "true"
: user.using_aircon;
await db.User.update( await db.User.update(
{ {
nick_name: new_nick_name, nick_name: new_nick_name,
loc_code: new_loc_code, loc_code: new_loc_code,
using_aircon: new_using_aircon,
}, },
{ where: { email: decoded.email } } { where: { email: decoded.email } }
); );
...@@ -269,3 +262,28 @@ export const postEditProfile = async (req, res) => { ...@@ -269,3 +262,28 @@ export const postEditProfile = async (req, res) => {
res.json({ msg: resForm.msg.err, contents: { error: err } }); res.json({ msg: resForm.msg.err, contents: { error: err } });
} }
}; };
// 에어컨 사용 변경 요청 처리
export const getToggleAircon = async (req, res) => {
const {
cookies: { acs_token },
} = req;
try {
const decoded = jwt.decode(acs_token);
const result_preuser = await db.User.findAll({
where: { email: decoded.email },
logging: false,
});
await db.User.update(
{ using_aircon: !result_preuser[0].using_aircon },
{ where: { email: decoded.email } }
);
res.json({ msg: resForm.msg.ok, contents: {} });
} catch (err) {
console.log(err);
res.json({ msg: resForm.msg.err, contents: { error: err } });
}
};
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
postLogin, postLogin,
getLogout, getLogout,
postSignup, postSignup,
getToggleAircon,
} from "../controllers/userController"; } from "../controllers/userController";
import { onlyPrivate } from "../middlewares"; import { onlyPrivate } from "../middlewares";
...@@ -31,5 +32,6 @@ globalRouter.get(routes.confirm, getConfirm); ...@@ -31,5 +32,6 @@ globalRouter.get(routes.confirm, getConfirm);
// User Info // User Info
globalRouter.get(routes.userinfo, onlyPrivate, getUserInfo); globalRouter.get(routes.userinfo, onlyPrivate, getUserInfo);
globalRouter.post(routes.editProfile, onlyPrivate, postEditProfile); globalRouter.post(routes.editProfile, onlyPrivate, postEditProfile);
globalRouter.post(routes.toggleAircon, onlyPrivate, getToggleAircon);
export default globalRouter; export default globalRouter;
...@@ -22,7 +22,7 @@ const CONFIRM = "/confirm"; ...@@ -22,7 +22,7 @@ const CONFIRM = "/confirm";
// # User Info // # User Info
const USER_INFO = "/user-info"; const USER_INFO = "/user-info";
const SET_LOCCODE = "/set-loccode"; const TOGGLE_AIRCON = "/toggle-aircon";
const EDIT_PROFILE = "/edit-profile"; const EDIT_PROFILE = "/edit-profile";
// # Detail Object // # Detail Object
...@@ -41,7 +41,7 @@ const routes = { ...@@ -41,7 +41,7 @@ const routes = {
confirm: CONFIRM, confirm: CONFIRM,
userinfo: USER_INFO, userinfo: USER_INFO,
editProfile: EDIT_PROFILE, editProfile: EDIT_PROFILE,
setLoccode: SET_LOCCODE, toggleAircon: TOGGLE_AIRCON,
Detail: (id) => { Detail: (id) => {
if (id) { if (id) {
return `/${id}`; return `/${id}`;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment