Skip to content

Commit

Permalink
develop와 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
codeing999 committed Jul 10, 2023
2 parents 245d007 + 4943bb9 commit a2c1b51
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 81 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#lib
node_modules
package-lock.json
#dist
dist

#git에 올라갈 때 쯤에는 이 환경변수들을 사용할 수 없어요!
##env
#.env
##secret
#src/module/auth/constants.ts

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@ lerna-debug.log*
#.env
.env

# constants
/src/module/auth/constants.ts

./src/__tests__/reservation/*
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:latest
LABEL authors="kjjdsa"

ENTRYPOINT ["top", "-b"]

# 베이스 이미지 선택
FROM node:18

# 작업 디렉토리 설정
WORKDIR /src

# 앱 종속성 설치
COPY package.json ./
RUN npm install

# 앱 소스 코드 복사
COPY . .

# 포트 노출
EXPOSE 3000

# mysql 서버가 실행되기 전에 앱이 실행되는것을 막아주는 스크립트래요. 이게 문제였던건 아닌것 같지만 사용했습니당
ADD https://github.com/vishnubob/wait-for-it/raw/master/wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh

# 앱 실행 명령
CMD /wait-for-it.sh mysql:3306 -- npm run start:seed
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'
services:
# 컨테이너
nest:
# 컨테이너의 호칭
container_name: v0.2
# 빌드에 사용하는 이미지 혹은 도커파일(저희의 경우 도커파일.)
build:
context: .
dockerfile: Dockerfile
# 외부 포트 : 내부 포트
ports:
- '3000:3000'
# 이 컨테이너에서 사용할 다른 컨테이너(docker compose 의 특장점?)
depends_on:
- mysql
mysql:
image: mysql:latest
# 비밀번호 값을 해시해서 보관하는 옵션을 준대요
command: --default-authentication-plugin=mysql_native_password
# 환경변수 설정
environment:
MYSQL_ROOT_PASSWORD: 1080
MYSQL_DATABASE: animalnest
ports:
- '3306:3306'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:seed": "ts-node src/seeder.ts && nest start --watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand Down
2 changes: 2 additions & 0 deletions setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE USER 'user'@'%' IDENTIFIED BY '1080';
GRANT CREATE, ALTER, INDEX, LOCK TABLES, REFERENCES, UPDATE, DELETE, DROP, SELECT, INSERT ON `animalnest`.* TO 'user'@'%';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DoctorService } from './doctor.service';
import { DoctorService } from '../../module/doctor/domain/doctor.service';

describe('DoctorService', () => {
let service: DoctorService;
Expand Down
12 changes: 3 additions & 9 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { PaymentService } from './module/payment/domain/payment.service';
import { AlarmModule } from './module/alarm/alarm.module';
import { AlarmServiceImpl } from './module/alarm/alarm.service';
import { DoctorModule } from './module/doctor/doctor.module';
import { DoctorEntity } from './module/doctor/doctor.entity';
import { DoctorEntity } from "./module/doctor/data/doctor.entity";

// Module 설명 : express에서는 router위주의 설계였다면, nest에서는 module위주의 설계를 한다
// 기능별로 module을 만들어서 여기에 다 넣어줄거임 - nest가 module간의 연결된걸 파악해서 한번에 실행해줌
Expand All @@ -35,20 +35,14 @@ import { DoctorEntity } from './module/doctor/doctor.entity';
ConfigModule.forRoot({ isGlobal: true, envFilePath: './.env' }),
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
username: process.env.DB_USER,
password: process.env.DB_PW,
database: process.env.DB_SCHEMA,
synchronize: false,
dropSchema: false,
entities: [
CounselingEntity,
PetEntity,
UserEntity,
PaymentEntity,
DoctorEntity,
],
entities: [CounselingEntity, PetEntity, UserEntity, PaymentEntity, DoctorEntity],
}),
TypeOrmModule.forFeature([CounselingEntity, DoctorEntity, UserEntity]),
CounselingModule,
Expand Down
3 changes: 1 addition & 2 deletions src/module/auth/auth.jwtAuthGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
UnauthorizedException,
} from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { jwtConstants } from './constants';
import { Request } from 'express';
import { AuthService } from "./domain/auth.service";

Expand All @@ -24,7 +23,7 @@ export class JwtAuthGuard implements CanActivate {
const payload = await this.jwtService.verifyAsync(
token,
{
secret: jwtConstants.secret
secret: process.env.JWT_SECRET_KEY
}
);
// 💡 We're assigning the payload to the request object here
Expand Down
3 changes: 3 additions & 0 deletions src/module/auth/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class jwtConstants {
static readonly secret: string = 'your_secret_key';
}
3 changes: 1 addition & 2 deletions src/module/auth/domain/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { JwtService } from '@nestjs/jwt';
import { LoginOutputDto } from "../../user/domain/user.output.dto";
import { LoginDto } from "../api/auth.dto";
import * as bcrypt from 'bcrypt';
import { jwtConstants } from "../constants";
import { AUTH_REPOSITORY, AuthRepository } from "./auth.repository";

@Injectable()
Expand All @@ -27,7 +26,7 @@ export class AuthService {
throw new UnauthorizedException('로그인에 실패하였습니다.');
}
const payload = { userId: user.id };
const accessToken = this.jwtService.sign({ payload },{ secret: jwtConstants.secret, expiresIn: '600s' });
const accessToken = this.jwtService.sign({ payload },{ secret: process.env.JWT_SECRET_KEY, expiresIn: '600s' });
return {
accessToken,
};
Expand Down
3 changes: 1 addition & 2 deletions src/module/auth/passport/jwt.passport.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// import { Injectable } from '@nestjs/common';
// import { PassportStrategy } from '@nestjs/passport';
// import { ExtractJwt, Strategy } from 'passport-jwt';
// import { jwtConstants } from '../constants';
//
// @Injectable()
// export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
// constructor() {
// super({
// jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), // header의 Bearer 이름 가진 토큰을 알아서 추출해옴
// secretOrKey: jwtConstants.secret,
// secretOrKey: process.env.JWT_SECRET_KEY,
// passReqToCallback: true,
// });
// }
Expand Down
2 changes: 1 addition & 1 deletion src/module/counseling/counseling.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CounselingRepositoryImpl } from './data/counseling.db';
import { CounselingEntity } from './data/counseling.entity';
import { COUNSELING_REPOSITORY } from './domain/counseling.repository';
import { AuthModule } from "../auth/auth.module";
import { DoctorEntity } from "../doctor/doctor.entity";
import { DoctorEntity } from "../doctor/data/doctor.entity";
import { PetEntity } from "../pet/data/pet.entity";

@Module({
Expand Down
4 changes: 2 additions & 2 deletions src/module/counseling/data/counseling.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { CounselingRepository } from '../domain/counseling.repository';
import { CounselingEntity } from './counseling.entity';
import { InvalidCounselingInfoError } from '../counseling.error';
import { CounselingMapper } from '../counseling.mapper';
import { DoctorEntity } from '../../doctor/doctor.entity';
import { PetEntity } from '../../value-data/pet.db';
import { DoctorEntity } from '../../doctor/data/doctor.entity';
import { PetEntity } from '../../pet/data/pet.entity';

//Injectable이 이걸 다른곳에 주입할수있단거 같음.
// Repository !== TypeOrm.Repsository => 완전한 Decoupling 을 달성할 수 있음 ! = > 이게 개발적으로 제가 생각하는 최적의 구조다. by 허재
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Repository } from "typeorm";
import { InjectRepository } from "@nestjs/typeorm";
import { Injectable } from "@nestjs/common";
import { plainToClass } from "class-transformer";
import { DoctorMapper } from "./doctor.mapper";
import { DoctorRepository } from "./docter.repository";
import { DoctorMapper } from "../doctor.mapper";
import { DoctorRepository } from "../domain/docter.repository";
import { DoctorEntity } from "./doctor.entity";
import { DoctorOutPutDto } from "./doctor.output.dto";
import { Doctor } from "./doctor.model";
import { DoctorOutPutDto } from "../domain/doctor.output.dto";
import { Doctor } from "../domain/doctor.model";
import { FactoryValue } from "nestjs-seeder";

@Injectable()
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/module/doctor/doctor.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from "@nestjs/common";
import { plainToClass } from "class-transformer";
import { DoctorOutPutDto } from "./doctor.output.dto";
import { DoctorEntity } from "./doctor.entity";
import { Doctor } from "./doctor.model";
import { DoctorOutPutDto } from "./domain/doctor.output.dto";
import { DoctorEntity } from "./data/doctor.entity";
import { Doctor } from "./domain/doctor.model";

@Injectable()
export class DoctorMapper {
Expand Down
8 changes: 4 additions & 4 deletions src/module/doctor/doctor.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Module } from '@nestjs/common';
import { DOCTOR_REPOSITORY } from "./docter.repository";
import { DoctorRepositoryImpl } from "./doctor.db";
import { DOCTOR_REPOSITORY } from "./domain/docter.repository";
import { DoctorRepositoryImpl } from "./data/doctor.db";
import { TypeOrmModule } from "@nestjs/typeorm";
import { DoctorEntity } from "./doctor.entity";
import { DoctorService } from './doctor.service';
import { DoctorEntity } from "./data/doctor.entity";
import { DoctorService } from './domain/doctor.service';

@Module({
imports: [
Expand Down
8 changes: 4 additions & 4 deletions src/module/doctor/doctor.seeder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Inject, Injectable } from "@nestjs/common";
import { DataFactory, FactoryValue, Seeder } from "nestjs-seeder";
import { DoctorRepositoryImpl } from "./doctor.db";
import { DoctorEntity } from "./doctor.entity";
import { Doctor } from "./doctor.model";
import { DOCTOR_REPOSITORY, DoctorRepository } from "./docter.repository";
import { DoctorRepositoryImpl } from "./data/doctor.db";
import { DoctorEntity } from "./data/doctor.entity";
import { Doctor } from "./domain/doctor.model";
import { DOCTOR_REPOSITORY, DoctorRepository } from "./domain/docter.repository";

@Injectable()
export class DoctorSeeder implements Seeder {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 8 additions & 5 deletions src/module/pet/data/pet.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ export class PetEntity {
@Column('varchar', { name: 'pet_type', length: 45 })
petType: string;

@Factory((faker) =>
faker.helpers.arrayElement(['cat', 'dog']) === 'cat'
? faker.animal.cat()
: faker.animal.dog(),
)
@Factory((faker, context: { petType: string }) => {
const petType = context.petType;
if (petType === 'dog') {
return faker.animal.dog();
} else if (petType === 'cat') {
return faker.animal.cat();
}
})
@Column('varchar', { name: 'breed', length: 45 })
breed: string;

Expand Down
92 changes: 53 additions & 39 deletions src/seeder.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
import { TypeOrmModule } from "@nestjs/typeorm";
import { seeder } from "nestjs-seeder";
import { DoctorEntity } from "./module/doctor/doctor.entity";
import { DoctorModule } from "./module/doctor/doctor.module";
import { DoctorSeeder } from "./module/doctor/doctor.seeder";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { UserSeeder } from "./module/user/user.seeder";
import { UserEntity } from "./module/user/data/user.entity";
import { UserModule } from "./module/user/user.module";
import { CounselingEntity } from "./module/counseling/data/counseling.entity";
import { PaymentEntity } from "./module/payment/data/payment.entity";
import { PetEntity } from "./module/pet/data/pet.entity";
import { PetSeeder } from "./module/pet/pet.seeder";
import { PetModule } from "./module/pet/pet.module";
import { TypeOrmModule } from '@nestjs/typeorm';
import { seeder } from 'nestjs-seeder';
import { DoctorEntity } from './module/doctor/data/doctor.entity';
import { DoctorModule } from './module/doctor/doctor.module';
import { DoctorSeeder } from './module/doctor/doctor.seeder';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { UserSeeder } from './module/user/user.seeder';
import { UserEntity } from './module/user/data/user.entity';
import { UserModule } from './module/user/user.module';
import { CounselingEntity } from './module/counseling/data/counseling.entity';
import { PaymentEntity } from './module/payment/data/payment.entity';
import { PetEntity } from './module/pet/data/pet.entity';
import { PetSeeder } from './module/pet/pet.seeder';
import { PetModule } from './module/pet/pet.module';

seeder({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
PetModule, UserModule, DoctorModule,
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
return {
type: 'mysql',
host: 'localhost',
port: Number(configService.get('DB_PORT')),
username: configService.get('DB_USER'),
password: configService.get('DB_PW'),
database: configService.get('DB_SCHEMA'),
autoLoadEntities: true,
synchronize: true,
dropSchema: true,
entities: [DoctorEntity,UserEntity, PetEntity, CounselingEntity,PaymentEntity],
}
}
}),
TypeOrmModule.forFeature([DoctorEntity,UserEntity, PetEntity, CounselingEntity,PaymentEntity]),
]
}).run([DoctorSeeder, UserSeeder, PetSeeder]);
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
PetModule,
UserModule,
DoctorModule,
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
return {
type: 'mysql',
host: configService.get('DB_HOST'),
port: Number(configService.get('DB_PORT')),
username: configService.get('DB_USER'),
password: configService.get('DB_PW'),
database: configService.get('DB_SCHEMA'),
autoLoadEntities: true,
synchronize: true,
dropSchema: true,
entities: [
DoctorEntity,
UserEntity,
PetEntity,
CounselingEntity,
PaymentEntity,
],
};
},
}),
TypeOrmModule.forFeature([
DoctorEntity,
UserEntity,
PetEntity,
CounselingEntity,
PaymentEntity,
]),
],
}).run([DoctorSeeder, UserSeeder, PetSeeder]);

0 comments on commit a2c1b51

Please sign in to comment.