Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepblock backend refatoring #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions controllers/projectController.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

const crypto = require("crypto");
const fs = require('fs');
const fsp = require('fs').promises;
const rimraf = require('rimraf');
const models = require("../models");
const path = require("@config/path");
const responseHandler = require('@utils/responseHandler');
const salt = process.env.SALT;
const crypto = require("crypto");
const fs = require('fs');
const rimraf = require('rimraf');
const models = require("../models");
const path = require("@config/path");
const responseHandler = require('@utils/responseHandler');
const salt = process.env.SALT;

module.exports = {
viewProjectList(req, res) {
Expand All @@ -16,32 +15,33 @@ module.exports = {
userID: req.session.userID,
}
})
.then((project_list) => {
if (!project_list.length) {
responseHandler.custom(res, 200, {
"result": "success",
"project_list": {}
});
} else {
let proj_arr = [];
for (var _project of project_list) {
_project = _project.dataValues;
proj_arr.push({
id: _project.id,
src: _project.projectName,
subtitle: _project.description
.then((project_list) => {
if (!project_list.length) {
responseHandler.custom(res, 200, {
"result": "success",
"project_info": {}
});
}
} else {
let proj_arr = [];
for (var _project of project_list) {
_project = _project.dataValues;
proj_arr.push({
projectID: _project.id,
image: null,
projectName: _project.projectName,
description: _project.description
});
}

responseHandler.custom(res, 200, {
"result": "success",
"project_list": proj_arr
});
}
})
.catch((err) => {
responseHandler.fail(res, 500, "처리 실패");
})
responseHandler.custom(res, 200, {
"result": "success",
"project_info": proj_arr
});
}
})
.catch((err) => {
responseHandler.fail(res, 500, "처리 실패");
})
},

async createProject(req, res) {
Expand Down Expand Up @@ -74,14 +74,14 @@ module.exports = {
transaction
});

fs.mkdir(user_project_path, ()=>{
fsp.mkdir(`${user_project_path}/result`)
fs.mkdirSync(user_project_path, () => {
fs.mkdirSync(`${user_project_path}/result`)
});
await transaction.commit();
let projectid = result.dataValues.id;
let project_id = result.dataValues.id;
responseHandler.custom(res, 200, {
"result": "success",
"project_id": projectid
"project_id": project_id
});
}
} catch (err) {
Expand All @@ -92,7 +92,7 @@ module.exports = {
}
}));
}
if(transaction) {
if (transaction) {
transaction.rollback();
}
responseHandler.fail(res, 500, "처리 실패");
Expand All @@ -114,7 +114,7 @@ module.exports = {

if (!user_project) {
transaction.rollback();
responseHandler.fail(res, 400, "잘못 된 접근입니다");
responseHandler.fail(res, 401, "잘못 된 접근입니다");
} else {
user_project_path = user_project.dataValues.projectPath;

Expand All @@ -133,7 +133,7 @@ module.exports = {
responseHandler.success(res, 200, "삭제 성공");
}
} catch (err) {
if(transaction) {
if (transaction) {
transaction.rollback();
}
responseHandler.fail(res, 500, "처리 실패");
Expand All @@ -157,7 +157,7 @@ module.exports = {

if (!before_project) {
transaction.rollback();
responseHandler.fail(res, 400, "잘못 된 접근입니다");
responseHandler.fail(res, 401, "잘못 된 접근입니다");
} else if (await models.Project.findOne({ where: { userID: req.session.userID, projectName: req.body.after } })) {
transaction.rollback();
responseHandler.fail(res, 409, "중복된 이름입니다");
Expand Down Expand Up @@ -192,7 +192,7 @@ module.exports = {
}
}));
}
if(transaction) {
if (transaction) {
transaction.rollback();
}
responseHandler.fail(res, 500, "처리 실패");
Expand Down
32 changes: 15 additions & 17 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const crypto = require("crypto");
const fs = require("fs");
const fsp = require("fs").promises;
const rimraf = require("rimraf");
const datauri = require("datauri");
const models = require("../models");
Expand Down Expand Up @@ -70,9 +69,9 @@ module.exports = {
);

fs.mkdirSync(userdir);
fsp.mkdir(`${userdir}/${path.project}`);
fsp.mkdir(`${userdir}/${path.dataset}`);
fsp.mkdir(`${userdir}/${path.profile}`);
fs.mkdirSync(`${userdir}/${path.project}`);
fs.mkdirSync(`${userdir}/${path.dataset}`);
fs.mkdirSync(`${userdir}/${path.profile}`);

const url = "http://" + `${server.ip}:${server.port}` +
"/api/verifyEmail?key=" + `${verifyKey}`
Expand All @@ -98,7 +97,6 @@ module.exports = {
if (transaction) {
transaction.rollback();
}
console.log(err);
responseHandler.fail(res, 500, "처리 실패");
}
},
Expand Down Expand Up @@ -433,9 +431,9 @@ module.exports = {
async changePassword(req, res) {
let transaction = null;

try{
try {
transaction = await models.sequelize.transaction();

const after_password = req.body.after_password;
const after_password_verify = req.body.after_password_verify;
const after_hash_password = crypto
Expand All @@ -444,32 +442,32 @@ module.exports = {
.digest("hex");

let user = await models.User.findOne({
where : {
id : req.session.userID
where: {
id: req.session.userID
}
});

console.log(user.dataValues.password);

if(after_password !== after_password_verify){
if (after_password !== after_password_verify) {
responseHandler.fail(res, 403, "비밀번호를 잘못 입력하셨습니다");
}else if(after_hash_password === user.dataValues.password){
} else if (after_hash_password === user.dataValues.password) {
responseHandler.fail(res, 403, "동일한 비밀번호로 바꿀 수 없습니다");
}else{
} else {
await models.User.update({
password : after_hash_password
password: after_hash_password
}, {
where : {
username : req.session.username
where: {
username: req.session.username
}
},{
}, {
transaction
});

await transaction.commit();
responseHandler.success(res, 200, "비밀번호 변경 완료");
}
}catch(err){
} catch (err) {
transaction.rollback();
responseHandler.fail(res, 500, "처리 실패");
}
Expand Down
3 changes: 1 addition & 2 deletions middlewares/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ module.exports = {
return next();
} else {
console.log("navi failed");
responseHandler.fail(res, 400, "잘못 된 접근")
responseHandler.fail(res, 403, "잘못 된 접근")
}
})
.catch((err) => {
console.log(err);
responseHandler.fail(res, 500, "처리 실패");
})
},
Expand Down
Loading