Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunmindev committed Nov 25, 2021
2 parents 020f7a6 + 3420f9b commit ec6baa7
Show file tree
Hide file tree
Showing 214 changed files with 5,144 additions and 1,068 deletions.
78 changes: 78 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
"passport-github": "^1.1.0",
"passport-google-oauth": "^2.0.0",
"passport-jwt": "^4.0.0",
"passport-kakao": "^1.0.1",
"prettier": "^2.4.1",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.9.0"
},
"devDependencies": {
"@types/passport-kakao": "^0.2.1",
"@types/cheerio": "^0.22.30",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.12",
Expand Down
2 changes: 2 additions & 0 deletions backend/src/loaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import passportLoader from 'src/loaders/passportLoader';
import passportJWTLoader from 'src/loaders/passportJWTLoader';
import passportGoogleLoader from 'src/loaders/passportGoogleLoader';
import passportGithubLoader from 'src/loaders/passportGithubLoader';
import passportKakaoLoader from 'src/loaders/passportKakaoLoader';
import routerLoader from 'src/loaders/routerLoader';
import corsLoader from 'src/loaders/corsLoader';

Expand All @@ -16,6 +17,7 @@ export default function init(app: express.Application) {
passportJWTLoader();
passportGoogleLoader();
passportGithubLoader();
passportKakaoLoader();
corsLoader(app);
routerLoader(app);
}
25 changes: 5 additions & 20 deletions backend/src/loaders/passportGithubLoader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as passport from 'passport';
import * as GitHubStrategy from 'passport-github';
import { User } from 'src/models';

import { UserService } from 'src/services';

export default function passportGithubLoader(): void {
const githubStrategyOptions = {
Expand All @@ -15,26 +12,14 @@ export default function passportGithubLoader(): void {
accessToken: string,
refreshToken: string,
profile: any,
cb: any,
done: any,
) => {
try {
const { id, login: username } = profile._json;
const userIsExist = await UserService.existGithubUser(username);
let user;
if (userIsExist) {
const temp = await UserService.updateGithubUserInfo(username, { githubUsername: username });
user = { userID: temp };
} else {
user = await UserService.findOrCreateUserForProvider({
authProvider: 'github',
authProviderID: id,
githubUsername: username,
});
}

return cb(null, user);
const { id, username } = profile;
const user = { id, username };
return done(null, user);
} catch (err) {
return cb(err);
return done(err);
}
};

Expand Down
3 changes: 2 additions & 1 deletion backend/src/loaders/passportGoogleLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as passport from 'passport';
import { OAuth2Strategy as GoogleStrategy, VerifyFunction } from 'passport-google-oauth';

import { UserService } from 'src/services';
import * as passport from 'passport';

export default function passportGoogleLoader() {
const googleStrategyOptions = {
Expand Down
3 changes: 1 addition & 2 deletions backend/src/loaders/passportJWTLoader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as express from 'express';
import {
Strategy as JWTStrategy,
ExtractJwt,
Expand Down Expand Up @@ -31,7 +30,7 @@ export default function passportJWTLoader(): void {
const verifyUser = async (jwtPayload: User, done: VerifiedCallback) => {
try {
const user: User = { userID: jwtPayload.userID! };
if (!user || !(await UserService.existsUser(user))) {
if (!user || !(await UserService.existsUserForUserID(user.userID))) {
return done(null, false);
}
return done(null, user);
Expand Down
27 changes: 27 additions & 0 deletions backend/src/loaders/passportKakaoLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Strategy as KakaoStrategy } from 'passport-kakao';
import * as passport from 'passport';

import { UserService } from 'src/services';

export default function passportKakaoLoader() {
const kakaoStrategyOptions = {
clientID: process.env.KAKAO_CLIENT_ID!,
clientSecret: process.env.KAKAO_SECRET_ID!,
callbackURL: process.env.KAKAO_CALLBACK_URL!,
};

const verifyKakaoUser = async (
accessToken: string,
refreshToken: string,
profile: any,
done: (error: any, user?: any, info?: any) => void,
) => {
const user = await UserService.findOrCreateUserForProvider({
authProvider: 'kakao',
authProviderID: profile.id,
});
done(null, user);
};

passport.use('kakao', new KakaoStrategy(kakaoStrategyOptions, verifyKakaoUser));
}
6 changes: 5 additions & 1 deletion backend/src/models/DashboardRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { Validate } from 'src/utils';
const dashboardRepositorySchema = new Schema<DashboardRepositoryType>(
{
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
title: { type: String },
repoName: { type: String, required: true },
repoUrl: { type: String, required: true },
starCount: { type: Number },
forkCount: { type: Number },
content: { type: String },
languageInfo: { type: Object },
},
{ versionKey: false, timestamps: true },
);
Expand Down
10 changes: 10 additions & 0 deletions backend/src/models/Notify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { model, Schema, Types } from 'mongoose';
import * as mongooseLeanVirtuals from 'mongoose-lean-virtuals';

import { NotifyType } from 'src/types';
import { Validate } from 'src/utils';
Expand Down Expand Up @@ -29,4 +30,13 @@ const notifySchema = new Schema<NotifyType>(
{ versionKey: false, timestamps: { createdAt: true, updatedAt: false } },
);

notifySchema.virtual('user', {
ref: 'User',
localField: 'senderID',
foreignField: '_id',
justOne: true,
});

notifySchema.plugin(mongooseLeanVirtuals);

export default model<NotifyType>('Notify', notifySchema);
18 changes: 5 additions & 13 deletions backend/src/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@ import { Validate } from 'src/utils';

const postSchema = new Schema<PostType>(
{
title: { type: String, trim: true },
content: { type: String, required: true, trim: true },
userID: { type: Types.ObjectId, required: true, ref: 'User', validate: Validate.userObjectID },
tags: {
type: [{ type: Types.ObjectId, ref: 'Tag', required: true, validate: Validate.tagObjectID }],
default: [],
},
type: {
type: String,
enum: ['normal', 'github', 'blog', 'algorithm'],
required: true,
default: 'normal',
},
link: { type: String, trim: true },
externalContent: { type: String, trim: true },
external: {
type: { type: String, enum: ['github', 'tistory', 'velog'] },
title: { type: String, trim: true },
content: { type: String, trim: true, require: true },
link: { type: String, trim: true },
info: Object,
type: { type: String, enum: ['repository', 'tistory', 'velog', 'problem'] },
identity: { type: String, trim: true },
target: { type: String, trim: true },
},
blog: { type: String, enum: ['tistory', 'velog'] },
blogIdentity: String,
blogPostID: String,
},
{ versionKey: false, timestamps: true },
);
Expand Down
7 changes: 6 additions & 1 deletion backend/src/models/TechStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Schema, model } from 'mongoose';
import { TechStackType } from 'src/types';

const TechStackSchema = new Schema<TechStackType>(
{ techStack: { type: String, required: true }, color: { type: String, required: true } },
{
techStack: { type: String, required: true },
searchString: { type: String, required: true },
searchCon: { type: String },
color: { type: String, required: true },
},
{ versionKey: false },
);

Expand Down
6 changes: 5 additions & 1 deletion backend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const dashboardSchema = new Schema<DashboardType>(
email: { type: String, validate: [Validate.email, 'Email ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'] },
profileImage: { type: String, validate: [Validate.url, 'URL ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'] },
jobObjectives: [{ type: String, required: true }],
techStacks: { any: { type: [Types.ObjectId] } },
techStacks: { type: Object, validate: Validate.dashboardTechStacksID },
statistics: {
problem: Object,
reposLanguage: Object,
},
},
{ _id: false },
);
Expand Down
Loading

0 comments on commit ec6baa7

Please sign in to comment.