Skip to content

Commit 020f7a6

Browse files
authored
Merge pull request #109 from boostcampwm-2021/develop
0.2.1
2 parents eb10ded + e618248 commit 020f7a6

File tree

178 files changed

+5089
-1966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+5089
-1966
lines changed

backend/package-lock.json

Lines changed: 682 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"pm2": "pm2 restart node_modules/.bin/ts-node -- -r tsconfig-paths/register ./src/bin/www.ts"
88
},
99
"dependencies": {
10-
"@types/passport-github": "^1.1.6",
10+
"aws-sdk": "^2.348.0",
1111
"axios": "^0.24.0",
12+
"cheerio": "^1.0.0-rc.10",
1213
"cookie-parser": "~1.4.4",
1314
"cors": "^2.8.5",
1415
"debug": "~2.6.9",
@@ -18,8 +19,10 @@
1819
"js-base64": "^3.7.2",
1920
"jsonwebtoken": "^8.5.1",
2021
"mongoose": "^6.0.12",
22+
"mongoose-lean-virtuals": "^0.9.0",
2123
"morgan": "~1.9.1",
2224
"nanoid": "^3.1.30",
25+
"nodemailer": "^6.7.1",
2326
"passport": "^0.5.0",
2427
"passport-github": "^1.1.0",
2528
"passport-google-oauth": "^2.0.0",
@@ -29,13 +32,17 @@
2932
"routing-controllers": "^0.9.0"
3033
},
3134
"devDependencies": {
35+
"@types/cheerio": "^0.22.30",
3236
"@types/cookie-parser": "^1.4.2",
3337
"@types/cors": "^2.8.12",
3438
"@types/express": "^4.17.13",
3539
"@types/jsonwebtoken": "^8.5.5",
40+
"@types/mongoose-lean-virtuals": "^0.5.2",
3641
"@types/morgan": "^1.9.3",
3742
"@types/node": "^16.11.6",
43+
"@types/nodemailer": "^6.4.4",
3844
"@types/passport": "^1.0.7",
45+
"@types/passport-github": "^1.1.6",
3946
"@types/passport-google-oauth": "^1.0.42",
4047
"@types/passport-jwt": "^3.0.6",
4148
"@typescript-eslint/eslint-plugin": "^5.2.0",

backend/src/loaders/passportGithubLoader.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Application } from 'express';
21
import * as passport from 'passport';
32
import * as GitHubStrategy from 'passport-github';
3+
import { User } from 'src/models';
44

55
import { UserService } from 'src/services';
66

@@ -19,10 +19,19 @@ export default function passportGithubLoader(): void {
1919
) => {
2020
try {
2121
const { id, login: username } = profile._json;
22-
const user = await UserService.findOrCreateUserForProvider({
23-
authProvider: 'github',
24-
authProviderID: id,
25-
});
22+
const userIsExist = await UserService.existGithubUser(username);
23+
let user;
24+
if (userIsExist) {
25+
const temp = await UserService.updateGithubUserInfo(username, { githubUsername: username });
26+
user = { userID: temp };
27+
} else {
28+
user = await UserService.findOrCreateUserForProvider({
29+
authProvider: 'github',
30+
authProviderID: id,
31+
githubUsername: username,
32+
});
33+
}
34+
2635
return cb(null, user);
2736
} catch (err) {
2837
return cb(err);

backend/src/models/Blog.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
3+
import { BlogType } from 'src/types/modelType';
4+
import { Validate } from 'src/utils';
5+
6+
const blogSchema = new Schema<BlogType>(
7+
{
8+
url: { type: String, required: true },
9+
identity: { type: String, required: true },
10+
type: { type: String, required: true, enum: ['tistory', 'velog'] },
11+
userID: { type: Types.ObjectId, required: true, validate: Validate.userObjectID },
12+
},
13+
{ versionKey: false, timestamps: false },
14+
);
15+
16+
export default model<BlogType>('Blog', blogSchema);

backend/src/models/Comment.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
3+
import { CommentType } from 'src/types/modelType';
4+
import { Validate } from 'src/utils';
5+
6+
const commentSchema = new Schema<CommentType>(
7+
{
8+
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
9+
postID: { type: Types.ObjectId, required: true, ref: 'Post', validate: Validate.postObjectID },
10+
content: { type: String, required: true },
11+
},
12+
{ versionKey: false, timestamps: true },
13+
);
14+
15+
commentSchema.virtual('user', {
16+
ref: 'User',
17+
localField: 'userID',
18+
foreignField: '_id',
19+
justOne: true,
20+
});
21+
22+
commentSchema.virtual('post', {
23+
ref: 'Post',
24+
localField: 'postID',
25+
foreignField: '_id',
26+
justOne: true,
27+
});
28+
29+
export default model<CommentType>('Comment', commentSchema);

backend/src/models/CommentLike.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
import * as mongooseLeanVirtuals from 'mongoose-lean-virtuals';
3+
4+
import { CommentLikeType } from 'src/types/modelType';
5+
import { Validate } from 'src/utils';
6+
7+
const commentLikeSchema = new Schema<CommentLikeType>(
8+
{
9+
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
10+
commentID: {
11+
type: Types.ObjectId,
12+
required: true,
13+
ref: 'Comment',
14+
validate: Validate.commentObjectID,
15+
},
16+
},
17+
{ versionKey: false, timestamps: { createdAt: true, updatedAt: false } },
18+
);
19+
20+
commentLikeSchema.virtual('user', {
21+
ref: 'User',
22+
localField: 'userID',
23+
foreignField: '_id',
24+
justOne: true,
25+
});
26+
27+
commentLikeSchema.plugin(mongooseLeanVirtuals);
28+
29+
export default model<CommentLikeType>('CommentLike', commentLikeSchema);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
3+
import { DashboardHistoryType } from 'src/types/modelType';
4+
import { Validate } from 'src/utils';
5+
6+
const dashboardHistorySchema = new Schema<DashboardHistoryType>(
7+
{
8+
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
9+
content: { type: String },
10+
date: { type: Date },
11+
},
12+
{ versionKey: false },
13+
);
14+
15+
export default model<DashboardHistoryType>('DashboardHistory', dashboardHistorySchema);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
3+
import { DashboardRepositoryType } from 'src/types/modelType';
4+
import { Validate } from 'src/utils';
5+
6+
const dashboardRepositorySchema = new Schema<DashboardRepositoryType>(
7+
{
8+
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
9+
title: { type: String },
10+
content: { type: String },
11+
},
12+
{ versionKey: false, timestamps: true },
13+
);
14+
15+
export default model<DashboardRepositoryType>('DashboardRepository', dashboardRepositorySchema);

backend/src/models/EchoMessage.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
3+
import { EchoMessageType } from 'src/types';
4+
import { Validate } from 'src/utils';
5+
6+
const echoMessageSchema = new Schema<EchoMessageType>(
7+
{
8+
roomID: { type: Types.ObjectId, ref: 'User', validate: Validate.echoRoomObjectID },
9+
content: { type: String, required: true },
10+
isRead: { type: Boolean, default: false, required: true },
11+
},
12+
{ timestamps: { createdAt: true, updatedAt: false } },
13+
);
14+
15+
export default model<EchoMessageType>('EchoMessage', echoMessageSchema);

backend/src/models/EchoRoom.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import { Schema, model, Types } from 'mongoose';
22

3-
import { EchoRoomType, MessageType } from 'src/types';
3+
import { EchoRoomType } from 'src/types';
44
import { Validate } from 'src/utils';
55

6-
const messageSchema = new Schema<MessageType>(
7-
{
8-
userID: { type: Types.ObjectId, ref: 'User', validate: Validate.userObjectID },
9-
content: { type: String, required: true },
10-
isRead: { type: Boolean, default: false, required: true },
11-
},
12-
{ timestamps: true },
13-
);
14-
156
const echoRoomSchema = new Schema<EchoRoomType>(
167
{
178
users: [{ type: Types.ObjectId, ref: 'User', required: true, validate: Validate.userObjectID }],
18-
messages: [messageSchema],
199
},
20-
{ versionKey: false, timestamps: { createdAt: false, updatedAt: true } },
10+
{ versionKey: false },
2111
);
2212

2313
export default model<EchoRoomType>('EchoRoom', echoRoomSchema);

backend/src/models/Follow.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
import * as mongooseLeanVirtuals from 'mongoose-lean-virtuals';
3+
4+
import { FollowType } from 'src/types/modelType';
5+
import { Validate } from 'src/utils';
6+
7+
const followSchema = new Schema<FollowType>(
8+
{
9+
followID: {
10+
type: Types.ObjectId,
11+
required: true,
12+
ref: 'User',
13+
validate: Validate.userObjectID,
14+
},
15+
followerID: {
16+
type: Types.ObjectId,
17+
required: true,
18+
ref: 'User',
19+
validate: Validate.userObjectID,
20+
},
21+
},
22+
{ versionKey: false, timestamps: { createdAt: true, updatedAt: false } },
23+
);
24+
25+
followSchema.virtual('follow', {
26+
ref: 'User',
27+
localField: 'followID',
28+
foreignField: '_id',
29+
justOne: true,
30+
});
31+
32+
followSchema.virtual('follower', {
33+
ref: 'User',
34+
localField: 'followerID',
35+
foreignField: '_id',
36+
justOne: true,
37+
});
38+
39+
followSchema.plugin(mongooseLeanVirtuals);
40+
41+
export default model<FollowType>('Follow', followSchema);

backend/src/models/Image.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Schema, model, Types } from 'mongoose';
2+
3+
import { ImageType } from 'src/types/modelType';
4+
import { Validate } from 'src/utils';
5+
6+
const imageSchema = new Schema<ImageType>(
7+
{
8+
url: { type: String, required: true },
9+
targetID: {
10+
type: Types.ObjectId,
11+
required: true,
12+
ref: 'Post',
13+
validate: Validate.postObjectID,
14+
},
15+
},
16+
{ versionKey: false },
17+
);
18+
19+
export default model<ImageType>('Image', imageSchema);

backend/src/models/Language.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

backend/src/models/Notify.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { model, Schema, Types } from 'mongoose';
2+
23
import { NotifyType } from 'src/types';
34
import { Validate } from 'src/utils';
45

56
const notifySchema = new Schema<NotifyType>(
67
{
78
type: {
89
type: String,
9-
enum: ['postLike', 'postComment', 'commentLike', 'follow', 'follower'],
10+
enum: ['postComment', 'postLike', 'commentLike', 'follow'],
1011
required: true,
1112
},
1213
userID: {
@@ -16,9 +17,16 @@ const notifySchema = new Schema<NotifyType>(
1617
validate: Validate.userObjectID,
1718
index: true,
1819
},
20+
senderID: {
21+
type: Types.ObjectId,
22+
ref: 'User',
23+
required: true,
24+
validate: Validate.userObjectID,
25+
index: true,
26+
},
1927
postID: { type: Types.ObjectId, ref: 'Post', validate: Validate.postObjectID },
2028
},
21-
{ timestamps: { createdAt: true, updatedAt: false } },
29+
{ versionKey: false, timestamps: { createdAt: true, updatedAt: false } },
2230
);
2331

2432
export default model<NotifyType>('Notify', notifySchema);

backend/src/models/Post.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
11
import { Schema, model, Types } from 'mongoose';
2+
import * as mongooseLeanVirtuals from 'mongoose-lean-virtuals';
23

3-
import { CommentType, PostType, LikeType } from 'src/types/modelType';
4+
import { PostType } from 'src/types/modelType';
45
import { Validate } from 'src/utils';
56

6-
const likeSchema = new Schema<LikeType>(
7-
{
8-
userID: { type: Types.ObjectId, ref: 'User', required: true, validate: Validate.userObjectID },
9-
},
10-
{ _id: false, timestamps: { createdAt: true, updatedAt: false } },
11-
);
12-
13-
const commentSchema = new Schema<CommentType>(
14-
{
15-
userID: { type: Types.ObjectId, ref: 'User', required: true, validate: Validate.userObjectID },
16-
content: { type: String, required: true },
17-
likes: { type: [likeSchema], default: [] },
18-
},
19-
{ _id: true, timestamps: true },
20-
);
21-
227
const postSchema = new Schema<PostType>(
238
{
249
title: { type: String, trim: true },
2510
content: { type: String, required: true, trim: true },
2611
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
27-
githubUsername: { type: String, trim: true },
28-
images: {
29-
type: [{ type: String, validate: [Validate.url, 'URL 형식이 잘못되었습니다.'] }],
30-
default: [],
31-
},
32-
comments: { type: [commentSchema], default: [] },
33-
likes: { type: [likeSchema], default: [] },
3412
tags: {
3513
type: [{ type: Types.ObjectId, ref: 'Tag', required: true, validate: Validate.tagObjectID }],
3614
default: [],
3715
},
16+
type: {
17+
type: String,
18+
enum: ['normal', 'github', 'blog', 'algorithm'],
19+
required: true,
20+
default: 'normal',
21+
},
22+
link: { type: String, trim: true },
23+
externalContent: { type: String, trim: true },
24+
external: {
25+
type: { type: String, enum: ['github', 'tistory', 'velog'] },
26+
identity: { type: String, trim: true },
27+
target: { type: String, trim: true },
28+
},
29+
blog: { type: String, enum: ['tistory', 'velog'] },
30+
blogIdentity: String,
31+
blogPostID: String,
3832
},
3933
{ versionKey: false, timestamps: true },
4034
);
4135

36+
postSchema.virtual('user', {
37+
ref: 'User',
38+
localField: 'userID',
39+
foreignField: '_id',
40+
justOne: true,
41+
});
42+
43+
postSchema.plugin(mongooseLeanVirtuals);
44+
4245
export default model<PostType>('Post', postSchema);

0 commit comments

Comments
 (0)