From 97c08826424538db5648e19472dc6c32fa5662c9 Mon Sep 17 00:00:00 2001
From: Yunseong Choe <68419358+marunemo@users.noreply.github.com>
Date: Fri, 21 Oct 2022 15:07:40 +0000
Subject: [PATCH 01/11] [Feat]Create organizational chart api
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
조직도 api 생성 및 연결 작업 시작 #93
---
back-end/controllers/chartController.js | 240 ++++++++++++++++++
back-end/models/chartModel.js | 41 +++
back-end/routes/chartRoutes.js | 20 ++
back-end/server.js | 2 +
.../web-next/componenets/OrganizationForm.js | 18 +-
front-end/web-next/componenets/Organogram.js | 87 +++++--
6 files changed, 379 insertions(+), 29 deletions(-)
create mode 100644 back-end/controllers/chartController.js
create mode 100644 back-end/models/chartModel.js
create mode 100644 back-end/routes/chartRoutes.js
diff --git a/back-end/controllers/chartController.js b/back-end/controllers/chartController.js
new file mode 100644
index 00000000..effc1abc
--- /dev/null
+++ b/back-end/controllers/chartController.js
@@ -0,0 +1,240 @@
+const asyncHandler = require("express-async-handler");
+const Chart = require("../models/chartModel");
+const User = require("../models/userModel.js");
+const jwt = require("jsonwebtoken");
+
+//@description Get organizational chart as array list
+//@route GET /api/chart
+//@access Protected
+const getChart = asyncHandler(async (req, res) => {
+ const auth = req.headers.authorization;
+
+ if (!auth || !auth.startsWith('Bearer')) {
+ res.status(401);
+ throw new Error('토큰이 없거나 인증되지 않았습니다.');
+ }
+
+ try {
+ const token = auth.split(' ')[1];
+
+ const decoded = jwt.verify(token, process.env.JWT_SECRET);
+ const currentUser = await User.findById(decoded.id).select("-password");
+ const currentUnit = await currentUser.Unit?.Unitname;
+
+ if (!currentUnit)
+ throw new ReferenceError('사용자의 부대가 설정되지 않았습니다.');
+
+ const unitOrganization = await Chart.find({ Unit: { $eq: currentUnit } });
+ res.send(unitOrganization);
+ }
+ catch (error) {
+ if(error === ReferenceError) {
+ res.status(400);
+ throw new Error(error);
+ }
+
+ res.status(401);
+ throw new Error('잘못된 토큰입니다.');
+ }
+});
+
+//@description Add organizational chart
+//@route POST /api/chart/add
+//@access Protected
+const addChart = asyncHandler(async (req, res) => {
+ const {
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent
+ } = req.body;
+ const auth = req.headers.authorization;
+
+ if (!auth || !auth.startsWith('Bearer')) {
+ res.status(401);
+ throw new Error('토큰이 없거나 인증되지 않았습니다.');
+ }
+
+ if (!Name || !Rank) {
+ res.status(400);
+ throw new Error("모든 정보를 입력하세요.");
+ }
+
+ try {
+ const token = auth.split(' ')[1];
+
+ const decoded = jwt.verify(token, process.env.JWT_SECRET);
+ const currentUser = await User.findById(decoded.id).select("-password");
+ const currentUnit = await currentUser.Unit?.Unitname;
+
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
+ }
+
+ const newChart = Chart.create({
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent,
+ Unit: currentUnit
+ });
+
+ if (newChart) {
+ res.status(201).json({
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent,
+ Unit: currentUnit
+ })
+ }
+ else {
+ res.send(400);
+ throw new Error('조직도를 추가/수정할 수 없습니다.')
+ }
+ }
+ catch (error) {
+ res.status(401);
+ throw new Error('잘못된 토큰입니다.');
+ }
+});
+
+//@description Edit organizational chart
+//@route POST /api/chart/edit
+//@access Protected
+const editChart = asyncHandler(async (req, res) => {
+ const {
+ _id,
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent
+ } = req.body;
+ const auth = req.headers.authorization;
+
+ if (!auth || !auth.startsWith('Bearer')) {
+ res.status(401);
+ throw new Error('토큰이 없거나 인증되지 않았습니다.');
+ }
+
+ if (!_id || !Name || !Rank) {
+ res.status(400);
+ throw new Error("모든 정보를 입력하세요.");
+ }
+
+ try {
+ const token = auth.split(' ')[1];
+
+ const decoded = jwt.verify(token, process.env.JWT_SECRET);
+ const currentUser = await User.findById(decoded.id).select("-password");
+ const currentUnit = await currentUser.Unit?.Unitname;
+
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
+ }
+
+ const updatedChart = Chart.updateOne({ _id: _id }, {
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent,
+ Unit: currentUnit
+ });
+
+ if (updatedChart) {
+ res.status(200).json({
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent,
+ Unit: currentUnit
+ })
+ }
+ else {
+ res.send(400);
+ throw new Error('조직도를 추가/수정할 수 없습니다.')
+ }
+ }
+ catch (error) {
+ res.status(401);
+ throw new Error('잘못된 토큰입니다.');
+ }
+});
+
+//@description Delete organizational chart
+//@route POST /api/chart/delete
+//@access Protected
+const deleteChart = asyncHandler(async (req, res) => {
+ const { _id } = req.body;
+ const auth = req.headers.authorization;
+
+ if (!auth || !auth.startsWith('Bearer')) {
+ res.status(401);
+ throw new Error('토큰이 없거나 인증되지 않았습니다.');
+ }
+
+ if (!_id || !Name || !Rank) {
+ res.status(400);
+ throw new Error("모든 정보를 입력하세요.");
+ }
+
+ try {
+ const token = auth.split(' ')[1];
+
+ const decoded = jwt.verify(token, process.env.JWT_SECRET);
+ const currentUser = await User.findById(decoded.id).select("-password");
+ const currentUnit = await currentUser.Unit?.Unitname;
+
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
+ }
+
+ const deleteChart = Chart.remove({ _id: _id });
+
+ if (deleteChart) {
+ res.status(200);
+ }
+ else {
+ res.send(400);
+ throw new Error('조직도를 추가/수정할 수 없습니다.')
+ }
+ }
+ catch (error) {
+ res.status(401);
+ throw new Error('잘못된 토큰입니다.');
+ }
+});
+
+module.exports = {
+ getChart,
+ addChart,
+ editChart,
+ deleteChart
+};
diff --git a/back-end/models/chartModel.js b/back-end/models/chartModel.js
new file mode 100644
index 00000000..3ff26d4e
--- /dev/null
+++ b/back-end/models/chartModel.js
@@ -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;
diff --git a/back-end/routes/chartRoutes.js b/back-end/routes/chartRoutes.js
new file mode 100644
index 00000000..372a39b0
--- /dev/null
+++ b/back-end/routes/chartRoutes.js
@@ -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;
diff --git a/back-end/server.js b/back-end/server.js
index 4629c026..f34c8c75 100644
--- a/back-end/server.js
+++ b/back-end/server.js
@@ -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,
@@ -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();
diff --git a/front-end/web-next/componenets/OrganizationForm.js b/front-end/web-next/componenets/OrganizationForm.js
index bfc328a7..ee45e6ce 100644
--- a/front-end/web-next/componenets/OrganizationForm.js
+++ b/front-end/web-next/componenets/OrganizationForm.js
@@ -2,6 +2,15 @@ import { useState, useCallback, useEffect } from 'react';
import { Modal, Image, Row, Col, Select } from 'antd';
import Styles from '../styles/OrganizationForm.module.css';
+function InfoElement(props) {
+ return (
+
+
{props.label}
+
{props.content}
+
+ )
+}
+
function InputElement(props) {
return (
@@ -89,16 +98,11 @@ function OrganizationForm(props) {
-
- serializedEdit('unit', event.target.value)} />
-
-
- serializedEdit('position', event.target.value)} />
-
+
- serializedEdit('roles', event.target.value)} />
+ serializedEdit('position', event.target.value)} />
serializedEdit('email', event.target.value)} />
diff --git a/front-end/web-next/componenets/Organogram.js b/front-end/web-next/componenets/Organogram.js
index 43fca12a..53b6aacf 100644
--- a/front-end/web-next/componenets/Organogram.js
+++ b/front-end/web-next/componenets/Organogram.js
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useCallback } from 'react';
import { Tree, TreeNode } from 'react-organizational-chart';
import { Button, Image, Row, Col } from 'antd';
+import { getCookie } from 'cookies-next';
import OrganizationCard from './OrganizationCard';
import Styles from '../styles/Organogram.module.css';
@@ -83,8 +84,22 @@ function Organogram(props) {
const [orgDataTree, setOrgDataTree] = useState([]);
useEffect(() => {
- setOrgData(props.renderData);
- }, [props.renderData]);
+ fetch(process.env.NEXT_PUBLIC_BACKEND_ROOT + 'api/chart', {
+ 'method': 'GET',
+ 'headers': {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${getCookie('usercookie')}`
+ },
+ })
+ .then(response => response.json())
+ .then(data => {
+ console.log(data)
+ // const objectData = data.reduce((preData, node) => {
+ // preData[node._id] = node;
+ // }, {})
+ // setOrgData(objectData)
+ });
+ }, []);
useEffect(() => {
makeTree(orgData);
@@ -99,31 +114,59 @@ function Organogram(props) {
setCardOpened(true);
}, [setSelectedOrgInfo, setCardOpened]);
- const createNode = useCallback((node) => {
- // node key generate
- const randomKey = Math.random().toString(36).substring(2, 10);
- node['key'] = randomKey;
-
- setOrgData(treeNode => ({ ...treeNode, [randomKey]: node }));
+ const createNode = useCallback(async (node) => {
+ await fetch(process.env.NEXT_PUBLIC_BACKEND_ROOT + 'api/chart/add', {
+ 'method': 'POST',
+ 'headers': {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${getCookie('usercookie')}`
+ },
+ 'body': JSON.stringify(node)
+ })
+ .then(response => setOrgData(treeNode => ({ ...treeNode, [response._id]: node })))
}, [setOrgData]);
- const updateNode = useCallback((node) => {
- setOrgData(treeNode => ({ ...treeNode, [node.key]: node }));
+ const updateNode = useCallback(async (node) => {
+ await fetch(process.env.NEXT_PUBLIC_BACKEND_ROOT + 'api/chart/edit', {
+ 'method': 'POST',
+ 'headers': {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${getCookie('usercookie')}`
+ },
+ 'body': JSON.stringify(node)
+ }).then(response => setOrgData(treeNode => ({ ...treeNode, [response._id]: node })))
}, [setOrgData]);
- const deleteNode = useCallback((node) => {
- setOrgData(treeNode => {
- const nodeCopy = { ...treeNode };
-
- // Redirection for children of removed node
- const nodeChildren = Object.values(nodeCopy).filter((data) => data.parent == node.key);
- for (let child of nodeChildren)
- child.parent = node.parent;
+ const deleteNode = useCallback(async (node) => {
+ const nodeCopy = { ...orgData };
+
+ // Redirection for children of removed node
+ const nodeChildren = Object.values(nodeCopy).filter((data) => data.parent == node._id);
+ for (let child of nodeChildren) {
+ child.parent = node.parent;
+ await fetch(process.env.NEXT_PUBLIC_BACKEND_ROOT + 'api/chart/edit', {
+ 'method': 'POST',
+ 'headers': {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${getCookie('usercookie')}`
+ },
+ 'body': JSON.stringify(child)
+ });
+ }
- delete nodeCopy[node.key]
- return nodeCopy;
- });
- }, [setOrgData]);
+ await fetch(process.env.NEXT_PUBLIC_BACKEND_ROOT + 'api/chart/delete', {
+ 'method': 'POST',
+ 'headers': {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${getCookie('usercookie')}`
+ },
+ 'body': JSON.stringify(node)
+ })
+ .then(() => {
+ delete nodeCopy[node._id];
+ setOrgData(nodeCopy);
+ })
+ }, [orgData, setOrgData]);
const makeTree = useCallback((data) => {
// Deep Copy for object
From 75116af230d8b28002c252d042a9c351a8f57719 Mon Sep 17 00:00:00 2001
From: Yunseong Choe <68419358+marunemo@users.noreply.github.com>
Date: Sat, 22 Oct 2022 02:43:43 +0000
Subject: [PATCH 02/11] [Fix]Activate read chart data
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
조직도 데이터를 읽어오지 못하는 오류 수정
조직도 데이터를 읽을 때 조직도에 아무것도 없을 경우, 자기자신의 정보로 새로 생성할 수 있도록 설정
---
back-end/controllers/chartController.js | 204 +++++++-----------
back-end/controllers/reportControllers.js | 12 +-
front-end/web-next/componenets/MemoForm.js | 3 +-
.../web-next/componenets/OrganizationCard.js | 15 +-
.../web-next/componenets/OrganizationForm.js | 16 +-
front-end/web-next/componenets/Organogram.js | 18 +-
6 files changed, 101 insertions(+), 167 deletions(-)
diff --git a/back-end/controllers/chartController.js b/back-end/controllers/chartController.js
index effc1abc..902f100d 100644
--- a/back-end/controllers/chartController.js
+++ b/back-end/controllers/chartController.js
@@ -1,41 +1,28 @@
const asyncHandler = require("express-async-handler");
+const UnitM = require("../models/unitModel");
const Chart = require("../models/chartModel");
-const User = require("../models/userModel.js");
-const jwt = require("jsonwebtoken");
//@description Get organizational chart as array list
//@route GET /api/chart
//@access Protected
const getChart = asyncHandler(async (req, res) => {
- const auth = req.headers.authorization;
+ const currentUser = req.user;
+ const currentUnit = await UnitM.findOne({ _id: currentUser.Unit });
- if (!auth || !auth.startsWith('Bearer')) {
- res.status(401);
- throw new Error('토큰이 없거나 인증되지 않았습니다.');
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
}
- try {
- const token = auth.split(' ')[1];
-
- const decoded = jwt.verify(token, process.env.JWT_SECRET);
- const currentUser = await User.findById(decoded.id).select("-password");
- const currentUnit = await currentUser.Unit?.Unitname;
-
- if (!currentUnit)
- throw new ReferenceError('사용자의 부대가 설정되지 않았습니다.');
-
- const unitOrganization = await Chart.find({ Unit: { $eq: currentUnit } });
- res.send(unitOrganization);
- }
- catch (error) {
- if(error === ReferenceError) {
- res.status(400);
- throw new Error(error);
- }
-
- res.status(401);
- 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
@@ -52,31 +39,34 @@ const addChart = asyncHandler(async (req, res) => {
Email,
Parent
} = req.body;
- const auth = req.headers.authorization;
-
- if (!auth || !auth.startsWith('Bearer')) {
- res.status(401);
- throw new Error('토큰이 없거나 인증되지 않았습니다.');
- }
if (!Name || !Rank) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}
- try {
- const token = auth.split(' ')[1];
+ const currentUser = req.user;
+ const currentUnit = await currentUser.Unit?.Unitname;
- const decoded = jwt.verify(token, process.env.JWT_SECRET);
- const currentUser = await User.findById(decoded.id).select("-password");
- const currentUnit = await currentUser.Unit?.Unitname;
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
+ }
- if (!currentUnit) {
- res.status(400);
- throw new Error('사용자의 부대가 설정되지 않았습니다.');
- }
+ const newChart = await Chart.create({
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent,
+ Unit: currentUnit
+ });
- const newChart = Chart.create({
+ if (newChart) {
+ res.status(201).json({
Name,
Rank,
Position,
@@ -86,29 +76,11 @@ const addChart = asyncHandler(async (req, res) => {
Email,
Parent,
Unit: currentUnit
- });
-
- if (newChart) {
- res.status(201).json({
- Name,
- Rank,
- Position,
- DoDID,
- Number,
- MilNumber,
- Email,
- Parent,
- Unit: currentUnit
- })
- }
- else {
- res.send(400);
- throw new Error('조직도를 추가/수정할 수 없습니다.')
- }
+ })
}
- catch (error) {
- res.status(401);
- throw new Error('잘못된 토큰입니다.');
+ else {
+ res.send(400);
+ throw new Error('조직도를 추가/수정할 수 없습니다.')
}
});
@@ -127,31 +99,34 @@ const editChart = asyncHandler(async (req, res) => {
Email,
Parent
} = req.body;
- const auth = req.headers.authorization;
-
- if (!auth || !auth.startsWith('Bearer')) {
- res.status(401);
- throw new Error('토큰이 없거나 인증되지 않았습니다.');
- }
if (!_id || !Name || !Rank) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}
- try {
- const token = auth.split(' ')[1];
+ const currentUser = req.user;
+ const currentUnit = await currentUser.Unit?.Unitname;
- const decoded = jwt.verify(token, process.env.JWT_SECRET);
- const currentUser = await User.findById(decoded.id).select("-password");
- const currentUnit = await currentUser.Unit?.Unitname;
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
+ }
- if (!currentUnit) {
- res.status(400);
- throw new Error('사용자의 부대가 설정되지 않았습니다.');
- }
+ const updatedChart = Chart.updateOne({ _id: _id }, {
+ Name,
+ Rank,
+ Position,
+ DoDID,
+ Number,
+ MilNumber,
+ Email,
+ Parent,
+ Unit: currentUnit
+ });
- const updatedChart = Chart.updateOne({ _id: _id }, {
+ if (updatedChart) {
+ res.status(200).json({
Name,
Rank,
Position,
@@ -161,29 +136,11 @@ const editChart = asyncHandler(async (req, res) => {
Email,
Parent,
Unit: currentUnit
- });
-
- if (updatedChart) {
- res.status(200).json({
- Name,
- Rank,
- Position,
- DoDID,
- Number,
- MilNumber,
- Email,
- Parent,
- Unit: currentUnit
- })
- }
- else {
- res.send(400);
- throw new Error('조직도를 추가/수정할 수 없습니다.')
- }
+ })
}
- catch (error) {
- res.status(401);
- throw new Error('잘못된 토큰입니다.');
+ else {
+ res.send(400);
+ throw new Error('조직도를 추가/수정할 수 없습니다.')
}
});
@@ -192,43 +149,28 @@ const editChart = asyncHandler(async (req, res) => {
//@access Protected
const deleteChart = asyncHandler(async (req, res) => {
const { _id } = req.body;
- const auth = req.headers.authorization;
-
- if (!auth || !auth.startsWith('Bearer')) {
- res.status(401);
- throw new Error('토큰이 없거나 인증되지 않았습니다.');
- }
if (!_id || !Name || !Rank) {
res.status(400);
throw new Error("모든 정보를 입력하세요.");
}
- try {
- const token = auth.split(' ')[1];
-
- const decoded = jwt.verify(token, process.env.JWT_SECRET);
- const currentUser = await User.findById(decoded.id).select("-password");
- const currentUnit = await currentUser.Unit?.Unitname;
+ const currentUser = req.user;
+ const currentUnit = await currentUser.Unit?.Unitname;
- if (!currentUnit) {
- res.status(400);
- throw new Error('사용자의 부대가 설정되지 않았습니다.');
- }
+ if (!currentUnit) {
+ res.status(400);
+ throw new Error('사용자의 부대가 설정되지 않았습니다.');
+ }
- const deleteChart = Chart.remove({ _id: _id });
+ const deleteChart = Chart.remove({ _id: _id });
- if (deleteChart) {
- res.status(200);
- }
- else {
- res.send(400);
- throw new Error('조직도를 추가/수정할 수 없습니다.')
- }
+ if (deleteChart) {
+ res.status(200);
}
- catch (error) {
- res.status(401);
- throw new Error('잘못된 토큰입니다.');
+ else {
+ res.send(400);
+ throw new Error('조직도를 추가/수정할 수 없습니다.')
}
});
@@ -237,4 +179,4 @@ module.exports = {
addChart,
editChart,
deleteChart
-};
+};
\ No newline at end of file
diff --git a/back-end/controllers/reportControllers.js b/back-end/controllers/reportControllers.js
index b1786cc3..dc24e2b8 100644
--- a/back-end/controllers/reportControllers.js
+++ b/back-end/controllers/reportControllers.js
@@ -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
@@ -26,7 +24,6 @@ const addReportCard = asyncHandler(async (req, res) => {
Invited,
Content,
Title,
- UserToken
} = req.body;
if (!Type || !ReportingSystem || !Invited || !Content || !Title) {
@@ -34,12 +31,9 @@ const addReportCard = asyncHandler(async (req, res) => {
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,
diff --git a/front-end/web-next/componenets/MemoForm.js b/front-end/web-next/componenets/MemoForm.js
index eb37a6db..c68a2ffd 100644
--- a/front-end/web-next/componenets/MemoForm.js
+++ b/front-end/web-next/componenets/MemoForm.js
@@ -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/', {
diff --git a/front-end/web-next/componenets/OrganizationCard.js b/front-end/web-next/componenets/OrganizationCard.js
index 2ebcc302..329152f3 100644
--- a/front-end/web-next/componenets/OrganizationCard.js
+++ b/front-end/web-next/componenets/OrganizationCard.js
@@ -66,23 +66,22 @@ function OrganizationCard(props) {
- {props.data.name}
- {props.data.rank}
+ {props.data.Name}
+ {props.data.Rank}
{props.data.DoDID}
-
-
+
-
-
+
+
-
-
+
+
-
serializedEdit('name', event.target.value)} />
+
serializedEdit('name', event.target.value)} />