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

sync: main -> develop #228

Open
wants to merge 5 commits into
base: develop
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
184 changes: 182 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,183 @@
<img src="https://user-images.githubusercontent.com/61582017/235365397-a488b602-2513-4bd3-af0b-1c919d4ba35d.png" width=33%><img src="https://user-images.githubusercontent.com/61582017/235365068-3f51cc30-7881-4381-957f-4baaf98c4edf.png" width="33%"><img src="https://user-images.githubusercontent.com/61582017/235365056-f5b78e90-cee1-47b1-b5c4-b9687a1b139b.png" width="33%">
<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 -->
<a id="readme-top"></a>
<!--
*** Thanks for checking out the Best-README-Template. If you have a suggestion
*** that would make this better, please fork the repo and create a pull request
*** or simply open an issue with the tag "enhancement".
*** Don't forget to give the project a star!
*** Thanks again! Now go create something AMAZING! :D
-->

웹 서비스 가보자고 &rarr; [Piickle](https://www.piickle.link/?utm_content=git1.2)


<!-- PROJECT SHIELDS -->
<!--
*** I'm using markdown "reference style" links for readability.
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
*** See the bottom of this document for the declaration of the reference variables
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
-->
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]



<!-- PROJECT LOGO -->
<br />
<div align="center">

[//]: # ( <a href="https://github.com/TeamPiickle/server">)

[//]: # ( <img src="images/logo.png" alt="Logo" width="80" height="80">)

[//]: # ( </a>)
<img src="https://user-images.githubusercontent.com/47105088/223893873-97a6f639-3a8c-4bb7-aee8-b92c7d4ba55b.png" >
<h3 align="center">Piickle server</h3>

<p align="center">
웹서비스 피클의 서버 저장소
<br />
<br />
·
<a href="https://github.com/TeamPiickle/server/issues/new?labels=bug&template=bug-report---.md">Report Bug</a>
·
<a href="https://github.com/TeamPiickle/server/issues/new?labels=enhancement&template=feature-request---.md">Request Feature</a>
</p>
</div>


<!-- ABOUT THE PROJECT -->

## 🥒 Piickle
### 지금 내게 필요한 대화주제 추천 서비스, 피클!

<aside>

#### 📍 1. 어색한 분위기 또는 침묵의 발생

>필연적으로 발생하는 과정을 매끄러운 아이스브레이킹 과정을 통해서 넘길 수 있다면, 그리고 보다 서로에 대해 더 알 수 있도록 설계할 수 있다면 충분히 해결가능하다고 판단했습니다.

-> 적절한 아이스브레이킹용 주제를 제시하며 대화주제 추천

#### 📍 2. 오락과 재미에 치중된 대화에서 오는 회의감

>재미있으면서도 진중한 대화 or 재미있는 주제에서 이어지는 진중한 대화를 만들어 가고자 합니다.

-> 가볍고 유쾌한 주제에서 출발해서 깊고 진중한 대화까지의 자연스러운 추천 흐름

#### 📍 3. 사람들이 공감하고, 집중할 수 있는 주제를 떠올리는 것에 있어서 한계

>사람들 간의 공통적인 주제를 모아서 직접 주제에 대한 선호도를 나누면 좋겠다고 생각했습니다.

-> 마음에 드는 주제를 북마크하고 모아서 볼 수 있도록 하는 아카이빙 기능

</aside>

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<br />

## Service Preview

### 1. Main
<img src="https://user-images.githubusercontent.com/47105088/223893885-097e274c-f54d-4b07-8468-530e441155a3.png">

### 2. Category

<img src="https://user-images.githubusercontent.com/47105088/223893891-6d6983a2-f5b2-4d0a-8cab-15e0af97b264.png">

### 3. Card
<img src="https://user-images.githubusercontent.com/47105088/223893903-bae45dac-7d8a-4ff4-a76b-d42e567a0b98.png">

### 4. My Piickle

<img src="https://user-images.githubusercontent.com/47105088/223893909-a5f6ad0b-277a-4536-8158-9fc302081131.png">

### 5. Piickle Me

<img src="https://user-images.githubusercontent.com/47105088/223893927-66b78377-9ee3-49ac-871d-a72d9321a663.png">

### 6. My Page

<img src="https://user-images.githubusercontent.com/47105088/223893939-73d8c9ad-170d-4239-8a7a-008e970109ab.png">

<br />


<!-- GETTING STARTED -->
## Getting Started

This is an example of how you may give instructions on setting up your project locally.
To get a local copy up and running follow these simple example steps.

### Installation

1. Clone the repo
```sh
git clone https://github.com/TeamPiickle/server.git
```
2. Install yarn packages
```sh
yarn
```
3. Enter your credentials in `.env`
4. Change git remote url to avoid accidental pushes to base project
```sh
git remote set-url origin TeamPiickle/server
git remote -v # confirm the changes
```

<p align="right">(<a href="#readme-top">back to top</a>)</p>



### Top contributors:

<a href="https://github.com/TeamPiickle/server/graphs/contributors">
<img src="https://contrib.rocks/image?repo=TeamPiickle/server" alt="contrib.rocks image" />
</a>



<!-- LICENSE -->
## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- CONTACT -->
## Contact

Kayoung Yoon - [email protected]

Project Link: [https://github.com/TeamPiickle/server](https://github.com/TeamPiickle/server)

<p align="right">(<a href="#readme-top">back to top</a>)</p>




<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/TeamPiickle/server.svg?style=for-the-badge
[contributors-url]: https://github.com/TeamPiickle/server/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/TeamPiickle/server.svg?style=for-the-badge
[forks-url]: https://github.com/TeamPiickle/server/network/members
[stars-shield]: https://img.shields.io/github/stars/TeamPiickle/server.svg?style=for-the-badge
[stars-url]: https://github.com/TeamPiickle/server/stargazers
[issues-shield]: https://img.shields.io/github/issues/TeamPiickle/server.svg?style=for-the-badge
[issues-url]: https://github.com/TeamPiickle/server/issues
[license-shield]: https://img.shields.io/github/license/TeamPiickle/server.svg?style=for-the-badge
[license-url]: https://github.com/TeamPiickle/server/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/linkedin_username
[product-screenshot]: images/screenshot.png
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"@sentry/node": "^7.57.0",
"@slack/client": "^5.0.2",
"@slack/webhook": "^7.0.2",
"@types/bcrypt": "^5.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/chai-things": "^0.0.35",
Expand Down
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import connectDB from './loaders/db';
import routes from './routes';
import helmet from 'helmet';
import errorHandler from './middlewares/errorHandler';
import * as SentryConfig from './loaders/sentryConfiguration';
import corsMiddleware from './middlewares/cors';
import config from './config';
import sessionConfiguration from './middlewares/session/sessionConfiguration';
Expand All @@ -14,15 +13,11 @@ app.use(express.json());
app.use(helmet());
app.use(corsMiddleware);
app.use(sessionConfiguration);
SentryConfig.initializeSentry(app);
app.use(routes);
SentryConfig.attachSentryErrorHandler(app);
app.use(errorHandler);

connectDB()
.then(() => {
console.log('db connected successfully.');
})
.then(() => {})
.catch(err => {
console.error(err);
process.exit(1);
Expand Down
29 changes: 0 additions & 29 deletions src/loaders/sentryConfiguration.ts

This file was deleted.

22 changes: 19 additions & 3 deletions src/middlewares/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { NextFunction, Request, Response } from 'express';
import { PiickleException } from '../intefaces/exception';
import statusCode from '../modules/statusCode';
import util from '../modules/util';
import { generateBlock } from '../modules/returnToSlack';
import { IncomingWebhook } from '@slack/webhook';
import config from '../config';

const webhook = new IncomingWebhook(config.slackWebHookUrl);
const errHandler = (
err: any,
req: Request,
Expand All @@ -13,9 +18,20 @@ const errHandler = (
.status(err.statusCode)
.send(util.fail(err.statusCode, err.message));
}
return res
.status(statusCode.INTERNAL_SERVER_ERROR)
.send(util.fail(statusCode.INTERNAL_SERVER_ERROR, (err as Error).message));

webhook
.send(generateBlock(req, err))
.then(() => {})
.catch(error => {
console.error(error);
})
.finally(() => {
return res
.status(statusCode.INTERNAL_SERVER_ERROR)
.send(
util.fail(statusCode.INTERNAL_SERVER_ERROR, (err as Error).message)
);
});
};

export default errHandler;
69 changes: 52 additions & 17 deletions src/modules/returnToSlack.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
import { Request } from 'express';
import { UserId } from '../types/types';
export const generateSlackMessage = (req: Request, error: any): string => {
import { IncomingWebhookSendArguments } from '@slack/webhook/dist/IncomingWebhook';

export const generateBlock = (
req: Request,
err: any
): IncomingWebhookSendArguments => {
const method = req.method.toUpperCase();
const originalUrl = req.originalUrl;
const uid = <UserId>req.user?.id;
const token = req.header('x-auth-token')?.split(' ')[1];

const reqInfo = {
host: req.header('Host'),
userAgent: req.header('User-Agent'),
user: req.user,
jwt: token,
body: req.body
const error = err as {
statusCode: number;
message: string;
stack: any;
};
return {
attachments: [
{
color: '#FF0000',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `[${method}] \`${originalUrl}\`\n- *statusCode*: ${error.statusCode}\n- *message*: ${error.message}`
}
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `
*Error 상세*\`\`\`${error.stack}\`\`\``
}
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `
*Request 상세*\`\`\`${JSON.stringify(
{
host: req.header('Host'),
userAgent: req.header('User-Agent'),
user: req.user,
jwt: token,
body: req.body
},
null,
2
)}\`\`\``
}
}
]
}
]
};
return `🚨 [${method}] \`${originalUrl}\`\n - *statusCode*: ${
error.statusCode
}\n - *message*: ${error.message} \`\`\`${JSON.stringify(
reqInfo,
null,
2
)}\`\`\``;
};
15 changes: 8 additions & 7 deletions src/services/mind23Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { Mind23CardResponseDto } from '../intefaces/mind23/Mind23CardResponseDto
import { QuestionResponseDto } from '../intefaces/mind23/QuestionResponseDto';
import { CommentDto } from '../intefaces/mind23/CommentDto';
import { Types } from 'mongoose';
import User from '../models/user/user';
import User, { UserDocument } from '../models/user/user';
import { Nullable } from '../types/types';
import config from '../config';

const NICKNAME_LIMIT = 8;
const findUserInfo = async (userId?: Types.ObjectId) => {
const findUserInfo = async (
userId?: Types.ObjectId
): Promise<Nullable<UserDocument>> => {
const user = await User.findOne({ _id: userId });
if (!user) {
throw new IllegalArgumentException('해당하는 아이디의 유저가 없습니다.');
}
return user;
};

Expand Down Expand Up @@ -49,8 +50,8 @@ const createCommentResponse = async (
_id: comment._id,
authorId: comment.author,
content: comment.content,
profileImageUrl: user.profileImageUrl,
nickname: user.nickname.slice(0, NICKNAME_LIMIT),
profileImageUrl: user?.profileImageUrl || config.defaultProfileImgUrl,
nickname: user?.nickname.slice(0, NICKNAME_LIMIT) || '탈퇴한 회원',
commentStatus: checkCommentStatus(comment.author, userId)
};
};
Expand Down
Loading