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

feat, setting: 회원가입 Validation, 응답폼 작성, 프로젝트 세팅 수정 #43

Merged
merged 11 commits into from
Nov 15, 2022
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@tanstack/react-query": "^4.16.1",
"axios": "^1.1.3",
"classnames": "^2.3.2",
"common": "1.0.0",
"@asnity/shared": "1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.3",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"private": true,

"workspaces": {
"packages": ["client","common", "server/**"],
"packages": ["client","shared", "server"],
"nohoist": ["server", "server/**"]
},
"scripts": {
"client": "yarn workspace client",
"server": "yarn workspace server",
"api-dev": "yarn workspace server api-dev",
"socket-dev": "yarn workspace server socket-dev"
}
Expand Down
2 changes: 2 additions & 0 deletions server/apps/api/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ConfigModule } from '@nestjs/config';
import { ChannelModule } from './channel/channel.module';
import { CommunityModule } from './community/community.module';
import { UserModule } from './user/user.module';
import { AuthModule } from './auth/auth.module';

@Module({
imports: [
Expand All @@ -17,6 +18,7 @@ import { UserModule } from './user/user.module';
UserModule,
ChannelModule,
CommunityModule,
AuthModule,
],
controllers: [ApiController],
providers: [ApiService],
Expand Down
13 changes: 13 additions & 0 deletions server/apps/api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Body, Controller, Post } from '@nestjs/common';
import { AuthService } from './auth.service';
import { SignUpDto } from './dto';

@Controller('api/user/auth')
export class AuthController {
constructor(private authService: AuthService) {}

@Post('signup')
signup(@Body() dto: SignUpDto) {
return this.authService.signup(dto);
}
}
15 changes: 15 additions & 0 deletions server/apps/api/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { UserRepository } from '@repository/user.repository';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from '@schemas/user.schema';

@Module({
imports: [
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
],
controllers: [AuthController],
providers: [AuthService, UserRepository],
})
export class AuthModule {}
23 changes: 23 additions & 0 deletions server/apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ForbiddenException, Injectable } from '@nestjs/common';
import { SignUpDto } from './dto';
import * as argon from 'argon2';
import { UserRepository } from '@repository/user.repository';
import { responseForm } from '@utils/responseForm';

@Injectable()
export class AuthService {
constructor(private userRepository: UserRepository) {}
async signup(dto: SignUpDto) {
const hash = await argon.hash(dto.password);
try {
await this.userRepository.create({ ...dto, password: hash });
} catch (error) {
if (error.name === 'MongoServerError' && error.code === 11000)
// 아이디 중복시 에러
throw new ForbiddenException('아이디가 중복되었습니다.');
throw error;
}

return responseForm('200', '회원가입 성공!');
}
}
4 changes: 0 additions & 4 deletions server/apps/api/src/user/auth/auth.controller.ts

This file was deleted.

9 changes: 0 additions & 9 deletions server/apps/api/src/user/auth/auth.module.ts

This file was deleted.

4 changes: 0 additions & 4 deletions server/apps/api/src/user/auth/auth.service.ts

This file was deleted.

14 changes: 7 additions & 7 deletions server/apps/api/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { User } from '@schemas/user.schema';
import { UserService } from '@user/user.service';
import { UserService } from './user.service';
import { CreateUserDto } from '@user/dto/create-user.dto';

@Controller('user')
export class UserController {
constructor(private userService: UserService) {}

@Get()
getUsers() {
const createUserDto: CreateUserDto = { id: 'ny', pw: 'nypw' };
this.userService.createUser(createUserDto);
return 'hello user';
}
// @Get()
// getUsers() {
// const createUserDto: CreateUserDto = { id: 'ny', pw: 'nypw' };
// this.userService.createUser(createUserDto);
// return 'hello user';
// }
// @Get('followers/:id')
// getFollowers(@Param('id') id: string): User[] {
// return this.usersService.getAllFollowers();
Expand Down
3 changes: 2 additions & 1 deletion server/apps/api/src/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { UserController } from '@user/user.controller';
import { UserService } from '@user/user.service';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from '@schemas/user.schema';
import { AuthModule } from '@user/auth/auth.module';
import { AuthModule } from '../auth/auth.module';
import { UserRepository } from '@repository/user.repository';
import { AuthController } from '../auth/auth.controller';

@Module({
imports: [
Expand Down
8 changes: 4 additions & 4 deletions server/apps/api/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export class UserService {
constructor(private readonly userRepository: UserRepository) {}

// getAllFollowers() {}

createUser(createUserDto: CreateUserDto) {
this.userRepository.create(createUserDto);
}
//
// createUser(createUserDto: CreateUserDto) {
// this.userRepository.create(createUserDto);
// }
}
4 changes: 2 additions & 2 deletions server/dao/repository/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { User, UserDocument } from '@schemas/user.schema';
import { Model } from 'mongoose';
import { CreateUserDto } from '@user/dto/create-user.dto';
import { SignUpDto } from '@api/src/auth/dto';

@Injectable()
export class UserRepository {
constructor(@InjectModel(User.name) private userModel: Model<UserDocument>) {}

async create(createUserDto: CreateUserDto) {
async create(createUserDto: SignUpDto) {
await this.userModel.create(createUserDto);
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion server/dao/schemas/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class User {

@Prop()
@IsString()
pw: string;
password: string;

@Prop()
@IsString()
Expand Down
5 changes: 3 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"test:e2e": "jest --config apps/socket/test/jest-e2e.json"
},
"dependencies": {
"@asnity/shared": "1.0.0",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"common": "1.0.0",
"argon2": "^0.30.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
Expand Down Expand Up @@ -79,4 +80,4 @@
"<rootDir>/apps/"
]
}
}
}
1 change: 1 addition & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@repository/*": ["dao/repository/*"],
"@utils/*": ["utils/*"],
"@user/*": ["apps/api/src/user/*"],
"@api/*": ["apps/api/*"],
}
}
}
6 changes: 6 additions & 0 deletions server/utils/responseForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const responseForm = (statusCode: string, data: any) => {
return {
statusCode,
result: data,
};
};
2 changes: 1 addition & 1 deletion common/package.json → shared/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "common",
"name": "@asnity/shared",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
Expand Down