Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from boostcamp-2020/web_release
Browse files Browse the repository at this point in the history
WEB : 2주차 release 버전 master 로 합침니다.
gitdog01 authored Nov 6, 2020
2 parents eaaa22c + 0328aef commit d1befa9
Showing 70 changed files with 18,972 additions and 494 deletions.
3 changes: 2 additions & 1 deletion BE/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@
"ts": "never",
"tsx": "never"
}
]
],
"import/no-unresolved": "off"
},
"settings": {
"import/resolver": {
7 changes: 7 additions & 0 deletions BE/depoly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
git stash
git checkout master
git pull
npm run build
pm2 stop npm
pm2 delete npm
pm2 start npm -- start
629 changes: 321 additions & 308 deletions BE/package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions BE/package.json
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
},
"dependencies": {
"@types/express-session": "^1.17.0",
"@types/jsonwebtoken": "^8.5.0",
"@types/passport": "^1.0.4",
"@types/passport-github": "^1.1.5",
"@types/passport-local": "^1.0.33",
@@ -37,6 +38,7 @@
"express-session": "^1.17.1",
"helmet": "^4.1.1",
"jsonwebtoken": "^8.5.1",
"module-alias": "^2.2.2",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"mysql2": "^2.2.5",
@@ -45,5 +47,13 @@
"passport-github": "^1.1.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0"
},
"_moduleAliases": {
"@root": "build",
"@controllers": "build/controllers",
"@interfaces": "build/interfaces",
"@models": "build/models",
"@providers": "build/providers",
"@routes": "build/routes"
}
}
26 changes: 18 additions & 8 deletions BE/src/app.ts
Original file line number Diff line number Diff line change
@@ -4,14 +4,21 @@ import session from "express-session";
import bodyParser from "body-parser";
import helmet from "helmet";

import index from "./routes/index";
import auth from "./routes/auth";
import milestone from "./routes/milestone";
import label from "./routes/label";
import issue from "./routes/issue";
import event from "./routes/event";
import index from "@routes/index";
import auth from "@routes/auth";
import milestone from "@routes/milestone";
import label from "@routes/label";
import issue from "@routes/issue";
import event from "@routes/event";
import tag from "@routes/tag";
import comment from "@routes/comment";
import assignee from "@routes/assignee";
import Passport from "@providers/passport";

import Passport from "./providers/passport";
import dotenv from "dotenv";
import path from "path";

dotenv.config({ path: path.join(__dirname, "../../.env") });

class App {
private app: Application;
@@ -42,7 +49,7 @@ class App {
this.app.use(passport.initialize());
this.app.use(
session({
secret: `@#@$MYSIGN#@$#$`,
secret: process.env.JWT_SECRET as string,
resave: false,
saveUninitialized: true,
})
@@ -58,6 +65,9 @@ class App {
this.app.use("/label", label);
this.app.use("/issue", issue);
this.app.use("/event", event);
this.app.use("/tag", tag);
this.app.use("/comment", comment);
this.app.use("/assignee", assignee);
}
}
export default App;
47 changes: 47 additions & 0 deletions BE/src/controllers/assignee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import { Request, Response } from "express";
import AssigneeModel from "@models/assignee";
import { Assignee } from "@interfaces/assignee";
import HTTPCODE from "@root/magicnumber";

const get = async (req: Request, res: Response): Promise<Response> => {
try {
const result = await AssigneeModel.select(+req.params.issueid);
return res.json(result);
} catch {
return res.sendStatus(HTTPCODE.SERVER_ERR);
}
};

const edit = async (req: Request, res: Response): Promise<Response> => {
try {
const data = await AssigneeModel.select(+req.params.issueid);
const ids = data.map((value) => Number(value.id));
for (const id of ids) {
const result = await AssigneeModel.del(id);
if (result === HTTPCODE.FAIL) return res.sendStatus(result);
if (result === HTTPCODE.SERVER_ERR) return res.sendStatus(result);
}
const issueId = Number(req.params.issueid);
const assignees = req.body.assignees.map((value: number) => {
const assignee: Assignee = {
id: null,
issue_id: issueId,
user_id: value,
};
return assignee;
});

for (const assignee of assignees) {
const result = await AssigneeModel.add(assignee);
if (result === HTTPCODE.FAIL) return res.sendStatus(result);
if (result === HTTPCODE.SERVER_ERR) return res.sendStatus(result);
}
return res.sendStatus(HTTPCODE.SUCCESS);
} catch {
return res.sendStatus(HTTPCODE.SERVER_ERR);
}
};

export default { get, edit };
68 changes: 49 additions & 19 deletions BE/src/controllers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
import { Request, Response } from "express";
import passport from "passport";
import jwt from "jsonwebtoken";
import dotenv from "dotenv";
import path from "path";

import userController from "@controllers/user";

dotenv.config({ path: path.join(__dirname, "../../.env") });

function login(req: Request, res: Response): void {
passport.authenticate("local", (err, userResult) => {
if (err || !userResult) {
return res.status(400).json({
message: "Something is not right",
user: userResult,
});
}
req.login(userResult, (error) => {
if (error) {
return res.send(error);
passport.authenticate(
"local",
async (err, userResult): Promise<any> => {
if (err || !userResult) {
return res.status(400).json({
message: "Something is not right",
});
}
return res.json({ userResult });
});
})(req, res);
const loginId = userResult.userID;
const rawPassword = userResult.password;
const searchResult = await userController.find(loginId, rawPassword);
if (searchResult) {
req.login(userResult, (error) => {
if (error) {
return res.send(error);
}
const JWT = jwt.sign(JSON.parse(JSON.stringify(userResult)), String(process.env.JWT_SECRET), { expiresIn: "10m" });
return res.json({ state: "success", JWT });
});
} else {
return res.json({ state: "fail" });
}
}
)(req, res);
}
function logout(req: Request, res: Response): any {
req.logout();
return res.json({ state: "success" });
function githubLogin(req: Request, res: Response): Response<JSON> | Response<string> {
const gitUser: any = req.user;
const userResult = gitUser.profile.username;
const JWT = jwt.sign(JSON.parse(JSON.stringify({ userResult })), String(process.env.JWT_SECRET), { expiresIn: "10m" });
return res.json({ state: "success", JWT });
}
function apple(req: Request, res: Response): Response<JSON> | Response<string> {
const loginUser: any = req.body;
const decoded: any = jwt.decode(loginUser.identity_token);
const userEmail: string = decoded.email;
const userResult = userEmail.split("@")[0];
const JWT = jwt.sign(JSON.parse(JSON.stringify({ userResult })), String(process.env.JWT_SECRET), { expiresIn: "10m" });
return res.json({ state: "success", JWT });
}
function githubLogin(req: Request, res: Response): any {

function logout(req: Request, res: Response): Response<JSON> {
req.logout();
return res.json({ state: "success" });
}
function githubLoginFail(req: Request, res: Response): any {

function githubLoginFail(req: Request, res: Response): Response<JSON> {
return res.json({ state: "fail" });
}
const github = passport.authenticate("github", { failureRedirect: "/auth/github/loginFail" });
export default { login, logout, githubLogin, githubLoginFail, github };
export default { login, logout, githubLogin, githubLoginFail, github, apple };
45 changes: 45 additions & 0 deletions BE/src/controllers/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Request, Response } from "express";
import CommentModel from "@models/comment";
import { Comment } from "@interfaces/comment";
import HTTPCODE from "@root/magicnumber";

const get = async (req: Request, res: Response): Promise<Response> => {
try {
const result = await CommentModel.select(+req.params.issueid);
return res.json(result);
} catch {
return res.sendStatus(HTTPCODE.SERVER_ERR);
}
};

const add = async (req: Request, res: Response): Promise<Response> => {
const comment: Comment = {
id: null,
issue_id: req.body.issue_id,
user_id: req.body.user_id,
body: req.body.body,
emoji: req.body.emoji,
created_at: new Date(),
};
const result = await CommentModel.add(comment);
return res.sendStatus(result);
};

const edit = async (req: Request, res: Response): Promise<Response> => {
const comment = {
id: req.body.id,
issue_id: req.body.issue_id,
user_id: req.body.user_id,
body: req.body.body,
emoji: req.body.emoji,
};
const result = await CommentModel.edit(comment);
return res.sendStatus(result);
};

const del = async (req: Request, res: Response): Promise<Response> => {
const result = await CommentModel.del(+req.body.id);
return res.sendStatus(result);
};

export default { get, add, edit, del };
28 changes: 28 additions & 0 deletions BE/src/controllers/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Request, Response } from "express";
import { Event } from "@interfaces/event";
import EventModel from "@models/event";
import HTTPCODE from "@root/magicnumber";

const get = async (req: Request, res: Response): Promise<Response<any>> => {
const { issueid } = req.params;
try {
const result = await EventModel.select(Number(issueid));
return res.json(result);
} catch {
return res.sendStatus(HTTPCODE.SERVER_ERR);
}
};

const add = async (req: Request, res: Response): Promise<Response<any>> => {
const event: Event = {
id: null,
issue_id: Number(req.params.issueid),
user_id: req.body.user_id,
log: req.body.log,
created_at: new Date(),
};
const result = await EventModel.add(event);
return res.sendStatus(result);
};

export default { get, add };
Empty file removed BE/src/controllers/index.ts
Empty file.
54 changes: 54 additions & 0 deletions BE/src/controllers/issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Request, Response } from "express";
import IssueModel from "@models/issue";
import { Issue } from "@interfaces/issue";
import HTTPCODE from "@root/magicnumber";

const get = async (req: Request, res: Response): Promise<any> => {
try {
const result = await IssueModel.select();
return res.json(result);
} catch {
return res.sendStatus(HTTPCODE.SERVER_ERR);
}
};

const add = async (req: Request, res: Response): Promise<any> => {
const issue: Issue = {
id: null,
title: req.body.title,
body: req.body.body,
user_id: req.body.author,
created_at: new Date(),
closed_at: req.body?.closed_at ?? null,
state: true,
milestone_id: req.body?.milestone_at ?? null,
};
const result = await IssueModel.add(issue);
return res.sendStatus(result);
};

const edit = async (req: Request, res: Response): Promise<any> => {
const issue = {
id: req.body.id,
title: req.body.title,
body: req.body.body,
user_id: req.body.author,
closed_at: req.body?.closed_at ?? null,
state: req.body.state,
milestone_id: req.body?.milestone_id ?? null,
};
const result = await IssueModel.edit(issue);
return res.sendStatus(result);
};

const del = async (req: Request, res: Response): Promise<any> => {
const result = await IssueModel.del(req.body.id);
return res.sendStatus(result);
};

const changeState = async (req: Request, res: Response): Promise<any> => {
const result = await IssueModel.changeState(+req.params.id, !!+req.params.state);
return res.sendStatus(result);
};

export default { get, add, edit, del, changeState };
43 changes: 43 additions & 0 deletions BE/src/controllers/label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Request, Response } from "express";
import LabelModel from "@models/label";
import { Label } from "@interfaces/label";
import HTTPCODE from "@root/magicnumber";

const get = async (req: Request, res: Response): Promise<any> => {
try {
const result = await LabelModel.select();
return res.json(result);
} catch {
return res.sendStatus(HTTPCODE.SERVER_ERR);
}
};

const add = async (req: Request, res: Response): Promise<any> => {
const label: Label = {
id: null,
name: req.body.name,
description: req.body.description,
color: req.body.color,
created_at: new Date(),
};
const result = await LabelModel.add(label);
return res.sendStatus(result);
};
const edit = async (req: Request, res: Response): Promise<any> => {
const label = {
id: req.body.id,
name: req.body.name,
description: req.body.description,
color: req.body.color,
};
const result = await LabelModel.edit(label);
return res.sendStatus(result);
};

const del = async (req: Request, res: Response): Promise<any> => {
const { id } = req.body;
const result = await LabelModel.del(id);
return res.sendStatus(result);
};

export default { get, add, edit, del };
Loading

0 comments on commit d1befa9

Please sign in to comment.