Skip to content

Commit

Permalink
Merge pull request #7 from osamhack2022-v2/api/backend
Browse files Browse the repository at this point in the history
pouring api/backend into web for front, back end integration
  • Loading branch information
s3kim2018 authored Oct 17, 2022
2 parents 79e898c + 384c309 commit d677c3e
Show file tree
Hide file tree
Showing 28 changed files with 834 additions and 2,450 deletions.
3 changes: 0 additions & 3 deletions back-end/.env.example

This file was deleted.

64 changes: 30 additions & 34 deletions back-end/ai/classifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const TheClassifier = require("classificator");
const Translator = require("nodepapago");
const posTagger = require("wink-pos-tagger");
Expand All @@ -21,38 +20,38 @@ let positive = [
`I am drooling over the awesome bean and cheese quesadillas.`
]
var negative = [
`Suicide`,
`urgent matter`,
'emergency situation',
`dead`,
'wire',
`secret`,
`classified`,
`attacked`,
`firearm`,
`unknown man has appeared`,
`in front of the guardhouse`,
`there are suspicious personnel`,
`in possession of a firearm`,
`A suspicious person has been found`,
`a landmine is in front of you`,
`My unit has been severly hurt`,
`hail weather snow advisory`,
`dangerous situation`,
'5 minute waiting group',
'North Korean provocation',
'Missle Launch',
'ammunition distribution',
'unusual occurrence',
`Gross, worst taco ever.`,
`The buritos gave me horrible diarrhea.`,
`I'm going to puke if I eat another bad nacho.`,
`I'd rather die than eat those nasty enchiladas.`,
'special has happened in the dormitory'
`Suicide`,
`urgent matter`,
'emergency situation',
`dead`,
'wire',
`secret`,
`classified`,
`attacked`,
`firearm`,
`unknown man has appeared`,
`in front of the guardhouse`,
`there are suspicious personnel`,
`in possession of a firearm`,
`A suspicious person has been found`,
`a landmine is in front of you`,
`My unit has been severly hurt`,
`hail weather snow advisory`,
`dangerous situation`,
'5 minute waiting group',
'North Korean provocation',
'Missle Launch',
'ammunition distribution',
'unusual occurrence',
`Gross, worst taco ever.`,
`The buritos gave me horrible diarrhea.`,
`I'm going to puke if I eat another bad nacho.`,
`I'd rather die than eat those nasty enchiladas.`,
'special has happened in the dormitory'
]
// classifier.addDocuments(positive, 'positive')
// classifier.addDocuments(negative, 'negative')

// classifier.train()

for (let i = 0; i < positive.length; i++) {
Expand Down Expand Up @@ -82,7 +81,7 @@ module.exports = async function (text) {
var taggedWord = words[i].value;
var tag = words[i].pos;
if (tag.includes('N') || tag.includes('V') || tag.includes('A'))
parsedtext = parsedtext + taggedWord + " "
parsedtext = parsedtext + taggedWord + " "
}
let classifieddata = classifier.categorize(parsedtext)
let score = classifieddata['likelihoods'][0]['proba']
Expand All @@ -99,6 +98,3 @@ module.exports = async function (text) {
}
}
//let { val } = await getScore('위병소 앞 총기를 든 거수자들이 나타났습니다. 자살하고싶어')



4 changes: 3 additions & 1 deletion back-end/config/generateToken.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const jwt = require("jsonwebtoken");

const generateToken = (id) => {
return jwt.sign({ id }, process.env.JWT_SECRET, {
return jwt.sign({
id
}, process.env.JWT_SECRET, {
expiresIn: "30d",
});
};
Expand Down
112 changes: 73 additions & 39 deletions back-end/controllers/chatControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@ const User = require("../models/userModel");
//@route POST /api/chat/
//@access Protected
const accessChat = asyncHandler(async (req, res) => {
const { userId } = req.body;
const {
userId
} = req.body;

if (!userId) {
console.log("잘못된 요청입니다.(UserId param not sent with request)");
return res.sendStatus(400);
}

var isChat = await Chat.find({
isGroupChat: false,
$and: [
{ users: { $elemMatch: { $eq: req.user._id } } },
{ users: { $elemMatch: { $eq: userId } } },
],
})
isGroupChat: false,
$and: [{
users: {
$elemMatch: {
$eq: req.user._id
}
}
},
{
users: {
$elemMatch: {
$eq: userId
}
}
},
],
})
.populate("users", "-password")
.populate("latestMessage");

Expand All @@ -39,7 +52,9 @@ const accessChat = asyncHandler(async (req, res) => {

try {
const createdChat = await Chat.create(chatData);
const FullChat = await Chat.findOne({ _id: createdChat._id }).populate(
const FullChat = await Chat.findOne({
_id: createdChat._id
}).populate(
"users",
"-password"
);
Expand All @@ -56,11 +71,19 @@ const accessChat = asyncHandler(async (req, res) => {
//@access Protected
const fetchChats = asyncHandler(async (req, res) => {
try {
Chat.find({ users: { $elemMatch: { $eq: req.user._id } } })
Chat.find({
users: {
$elemMatch: {
$eq: req.user._id
}
}
})
.populate("users", "-password")
.populate("groupAdmin", "-password")
.populate("latestMessage")
.sort({ updatedAt: -1 })
.sort({
updatedAt: -1
})
.then(async (results) => {
results = await User.populate(results, {
path: "latestMessage.sender",
Expand All @@ -79,7 +102,9 @@ const fetchChats = asyncHandler(async (req, res) => {
//@access Protected
const createGroupChat = asyncHandler(async (req, res) => {
if (!req.body.users || !req.body.name) {
return res.status(400).send({ message: "모든 정보를 입력하세요" });
return res.status(400).send({
message: "모든 정보를 입력하세요"
});
}

var users = JSON.parse(req.body.users);
Expand All @@ -100,7 +125,9 @@ const createGroupChat = asyncHandler(async (req, res) => {
groupAdmin: req.user,
});

const fullGroupChat = await Chat.findOne({ _id: groupChat._id })
const fullGroupChat = await Chat.findOne({
_id: groupChat._id
})
.populate("users", "-password")
.populate("groupAdmin", "-password");

Expand All @@ -115,17 +142,18 @@ const createGroupChat = asyncHandler(async (req, res) => {
// @route PUT /api/chat/rename
// @access Protected
const renameGroup = asyncHandler(async (req, res) => {
const { chatId, chatName } = req.body;
const {
chatId,
chatName
} = req.body;

const updatedChat = await Chat.findByIdAndUpdate(
chatId,
{
chatName: chatName,
},
{
new: true,
}
)
chatId, {
chatName: chatName,
}, {
new: true,
}
)
.populate("users", "-password")
.populate("groupAdmin", "-password");

Expand All @@ -141,19 +169,22 @@ const renameGroup = asyncHandler(async (req, res) => {
// @route PUT /api/chat/groupremove
// @access Protected
const removeFromGroup = asyncHandler(async (req, res) => {
const { chatId, userId } = req.body;
const {
chatId,
userId
} = req.body;

// check if the requester is admin

const removed = await Chat.findByIdAndUpdate(
chatId,
{
$pull: { users: userId },
},
{
new: true,
}
)
chatId, {
$pull: {
users: userId
},
}, {
new: true,
}
)
.populate("users", "-password")
.populate("groupAdmin", "-password");

Expand All @@ -169,19 +200,22 @@ const removeFromGroup = asyncHandler(async (req, res) => {
// @route PUT /api/chat/groupadd
// @access Protected
const addToGroup = asyncHandler(async (req, res) => {
const { chatId, userId } = req.body;
const {
chatId,
userId
} = req.body;

// check if the requester is admin

const added = await Chat.findByIdAndUpdate(
chatId,
{
$push: { users: userId },
},
{
new: true,
}
)
chatId, {
$push: {
users: userId
},
}, {
new: true,
}
)
.populate("users", "-password")
.populate("groupAdmin", "-password");

Expand Down
Loading

0 comments on commit d677c3e

Please sign in to comment.