Skip to content

Commit

Permalink
Merge pull request #20 from osamhack2022-v2/web_orgtree
Browse files Browse the repository at this point in the history
Pouring Web orgtree into Web for finishing organizational tree backend setting
  • Loading branch information
s3kim2018 authored Oct 22, 2022
2 parents 558e304 + a542c2a commit b9c8e35
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 104 deletions.
160 changes: 160 additions & 0 deletions back-end/controllers/chartController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
const asyncHandler = require("express-async-handler");
const UnitM = require("../models/unitModel");
const Chart = require("../models/chartModel");

//@description Get organizational chart as array list
//@route GET /api/chart
//@access Protected
const getChart = asyncHandler(async (req, res) => {
const currentUser = req.user;
const currentUnit = await UnitM.findOne({ _id: currentUser.Unit });

if (!currentUnit) {
res.status(400);
throw new Error('사용자의 부대가 설정되지 않았습니다.');
}

const unitOrganization = await Chart.find({ Unit: { $eq: currentUnit.Unitname } });
if (unitOrganization.length === 0) {
await Chart.create({
Name: currentUser.Name,
Rank: currentUser.Rank,
Unit: currentUnit.Unitname
})
}
res.send(unitOrganization);
});

//@description Add organizational chart
//@route POST /api/chart/add
//@access Protected
const addChart = asyncHandler(async (req, res) => {
const {
Name,
Rank,
Unit,
Position,
DoDID,
Number,
MilNumber,
Email,
Parent
} = req.body;

if (!Name || !Rank || !Unit) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}

const newChart = await Chart.create({
Name,
Rank,
Unit,
Position,
DoDID,
Number,
MilNumber,
Email,
Parent,
});

if (newChart) {
res.status(201).json({
_id: newChart._id,
Name,
Rank,
Unit,
Position,
DoDID,
Number,
MilNumber,
Email,
Parent: Parent ?? null,
})
}
else {
res.send(400);
throw new Error('조직도를 추가/수정할 수 없습니다.')
}
});

//@description Edit organizational chart
//@route POST /api/chart/edit
//@access Protected
const editChart = asyncHandler(async (req, res) => {
const {
_id,
Name,
Rank,
Unit,
Position,
DoDID,
Number,
MilNumber,
Email,
Parent
} = req.body;

if (!_id || !Name || !Rank || !Unit) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}

const updatedChart = await Chart.findByIdAndUpdate(_id, {
Name,
Rank,
Position,
DoDID,
Number,
MilNumber,
Email,
Parent,
Unit
});

if (updatedChart) {
res.status(200).json({
Name,
Rank,
Position,
DoDID,
Number,
MilNumber,
Email,
Parent,
Unit
})
}
else {
res.send(400);
throw new Error('조직도를 추가/수정할 수 없습니다.')
}
});

//@description Delete organizational chart
//@route POST /api/chart/delete
//@access Protected
const deleteChart = asyncHandler(async (req, res) => {
const { _id } = req.body;

if (!_id) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}

const deleteChart = await Chart.findByIdAndDelete(_id);
if (deleteChart) {
res.send(200);
}
else {
res.send(400);
throw new Error('조직도를 추가/수정할 수 없습니다.')
}
});

module.exports = {
getChart,
addChart,
editChart,
deleteChart
};
12 changes: 3 additions & 9 deletions back-end/controllers/reportControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const Reportsys = require("../models/reportModel");
const UnitM = require("../models/unitModel");
const UserM = require("../models/userModel");
const getScore = require('../ai/classifier.js')
var mongoose = require('mongoose');
const jwt = require("jsonwebtoken");

//@description Get all report cards
//@route GET /api/report
Expand All @@ -26,20 +24,16 @@ const addReportCard = asyncHandler(async (req, res) => {
Invited,
Content,
Title,
UserToken
} = req.body;

if (!Type || !ReportingSystem || !Invited || !Content || !Title) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}

//decodes token id
const decoded = jwt.verify(UserToken, process.env.JWT_SECRET);
const currentUser = await UserM.findById(decoded.id).select("-password");

let currentUnit = currentUser.Unit
let Severity = await getScore(Content)
const currentUser = req.user;
let currentUnit = currentUser.Unit;
let Severity = await getScore(Content);
const report = await Report.create({
User: currentUser,
Type,
Expand Down
41 changes: 41 additions & 0 deletions back-end/models/chartModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const mongoose = require("mongoose");

const chartModel = mongoose.Schema({
Name: {
type: String,
required: true
},
Rank: {
type: String,
required: true
},
Unit: {
type: String,
required: true
},
Position: {
type: String
},
DoDID: {
type: String
},
Number: {
type: String
},
MilNumber: {
type: String
},
Email: {
type: String
},
Parent: {
type: String,
default: null
}
}, {
timestamps: true
});

const Chart = mongoose.model("Chart", chartModel);

module.exports = Chart;
20 changes: 20 additions & 0 deletions back-end/routes/chartRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const express = require("express");
const {
getChart,
addChart,
editChart,
deleteChart
} = require('../controllers/chartController');
const {
protect,
onlyAdmin
} = require("../middleware/authMiddleware");

const router = express.Router();

router.route("/").get(protect, getChart);
router.route("/add").post(onlyAdmin, addChart);
router.route("/edit").post(onlyAdmin, editChart);
router.route("/delete").post(onlyAdmin, deleteChart);

module.exports = router;
2 changes: 2 additions & 0 deletions back-end/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const messageRoutes = require("./routes/messageRoutes");
const unitRoutes = require("./routes/unitRoutes");
const reportRoutes = require("./routes/reportRoutes");
const commentRoutes = require("./routes/commentRoutes");
const chartRoutes = require("./routes/chartRoutes");
const reportsysRoutes = require("./routes/reportsysRoutes");
const {
notFound,
Expand All @@ -33,6 +34,7 @@ app.use("/api/unit", unitRoutes);
app.use("/api/report", reportRoutes);
app.use("/api/comment", commentRoutes);
app.use("/api/reportsys", reportsysRoutes);
app.use("/api/chart", chartRoutes);


/*const __dirname1 = path.resolve();
Expand Down
3 changes: 1 addition & 2 deletions front-end/web-next/componenets/MemoForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ function MemoForm(props) {
Type: memoType,
ReportingSystem: reportOrgList.map((org) => (org.title)),
Invited: addUserList,
Content: memoContent,
UserToken: getCookie('usercookie')
Content: memoContent
}

await fetch(process.env.NEXT_PUBLIC_BACKEND_ROOT + 'api/report/', {
Expand Down
28 changes: 18 additions & 10 deletions front-end/web-next/componenets/OrganizationCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function OrganizationCard(props) {
return (
<>
<Modal
className="organizationCard"
open={props.isOpen}
onCancel={props.onClose}
footer={
Expand Down Expand Up @@ -57,45 +58,52 @@ function OrganizationCard(props) {
<Row
className={Styles.elementRow}
align="middle"
justify="center"
>
<Col>
<Image
className={Styles.profileImage}
src="https://images.pexels.com/photos/1202726/pexels-photo-1202726.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
/>
</Col>
</Row>
<Row
className={Styles.elementRow}
align="middle"
justify="center"
>
<Col className={Styles.userProfile}>
<div>
<span className={Styles.userName}>{props.data.name}</span>
<span className={Styles.milRank}>{props.data.rank}</span>
<span className={Styles.userName}>{props.data.Name}</span>
<span className={Styles.milRank}>{props.data.Rank}</span>
</div>
<div className={Styles.userDodid}>{props.data.DoDID}</div>
</Col>
</Row>
<Row className={Styles.elementRow}>
<Col span={12}><InfoElement label="부대" content={props.data.unit} /></Col>
<Col span={12}><InfoElement label="직책" content={props.data.position} /></Col>
<Col span={12}><InfoElement label="부대" content={props.data.Unit} /></Col>
<Col span={12}><InfoElement label="군번" content={props.data.DoDID} /></Col>
</Row>
<Row className={Styles.elementRow}>
<Col span={12}><InfoElement label="권한" content={props.data.roles} /></Col>
<Col span={12}><InfoElement label="이메일" content={props.data.email} /></Col>
<Col span={12}><InfoElement label="직책" content={props.data.Position} /></Col>
<Col span={12}><InfoElement label="이메일" content={props.data.Email} /></Col>
</Row>
<Row className={Styles.elementRow}>
<Col span={12}><InfoElement label="전화번호" content={props.data.number} /></Col>
<Col span={12}><InfoElement label="군연락망" content={props.data.milNumber} /></Col>
<Col span={12}><InfoElement label="전화번호" content={props.data.Number} /></Col>
<Col span={12}><InfoElement label="군연락망" content={props.data.MilNumber} /></Col>
</Row>
</Modal>
<OrganizationForm
isOpen={openCreateForm}
onClose={() => setOpenCreateForm(false)}
data={{ Unit: props.data.Unit }}
onSubmit={props.onCreate}
nodeList={props.nodeList}
/>
<OrganizationForm
isOpen={openUpdateForm}
onClose={() => setOpenUpdateForm(false)}
onSubmit={props.onUpdate}
data={props.data}
onSubmit={props.onUpdate}
nodeList={props.nodeList}
/>
</>
Expand Down
Loading

0 comments on commit b9c8e35

Please sign in to comment.