Skip to content

Commit

Permalink
[Edit] Edit index.js, user.js (#58)
Browse files Browse the repository at this point in the history
Edit routing GET '/logout' in index.js
Edit routing DELETE '/user' in user.js and try-catch syntax
  • Loading branch information
lcw921 authored and pec9399 committed Jun 7, 2018
1 parent 5476d9e commit 766fea6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 53 deletions.
12 changes: 3 additions & 9 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@ router.post('/login', wrap(async (req, res) => {

// logout
router.get('/logout', wrap(async (req, res) => {
try {
const destroy = await req.session.destroy;
if (destroy) {
res.redirect('/');
}
} catch (e) {
res.send({
result: false
});
const dest = await req.session.destroy();
if (dest) {
res.redirect('/');
}
}));

Expand Down
71 changes: 27 additions & 44 deletions server/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,35 @@ const wrap = require('express-async-wrap');

// add user
router.post('/', wrap(async (req, res) => {
try {
const create = await models.user.create(req.body);
if (create) {
res.send({
result: true
});
}
} catch (e) {
const create = await models.user.create(req.body);
if (create) {
res.send({
result: false
result: true
});
}
}));

// 유저 삭제
router.delete('/', wrap(async (req, res) => {
try {
if (req.session.user.auth === 1) {
const dest = await models.user.destroy({
where: { uid: req.body.uid }
});
if (dest) {
res.send({
result: true
});
} else {
}
} else if (req.session.user.uid === req.body.uid) {
const dest = await models.user.destroy({
where: { uid: req.body.uid }
});
if (dest) {
res.send({
result: false
result: true
});
}
} catch (e) {
} else {
res.send({
result: false
});
Expand All @@ -49,47 +48,31 @@ router.delete('/', wrap(async (req, res) => {

// 유저 정보 수정
router.put('/', wrap(async (req, res) => {
try {
const update = await models.user.update(req.body, {
where: {
uid: req.session.user.uid
}
});

if (update) {
res.send({
result: true
});
const update = await models.user.update(req.body, {
where: {
uid: req.session.user.uid
}
} catch (e) {
});

if (update) {
res.send({
result: false
result: true
});
}
}));


// 유저 정보 읽기
router.get('/:uid', wrap(async (req, res) => {
try {
const inform = await models.user.findOne({
where: {
uid: req.params.uid
}
});
await delete inform.dataValues.pw;

if (inform) {
res.send(inform);
} else {
res.send({
result: false
});
const inform = await models.user.findOne({
where: {
uid: req.params.uid
}
} catch (e) {
res.send({
result: false
});
});
await delete inform.dataValues.pw;

if (inform) {
res.send(inform);
}
}));

Expand Down

0 comments on commit 766fea6

Please sign in to comment.