From ef89a43cc90241b3a5760b5dc53d85e1e786bd01 Mon Sep 17 00:00:00 2001 From: Sejin Park Date: Wed, 26 Jul 2023 14:50:30 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=A4=91=20(paymentRepository,=20AlarmService=20&?= =?UTF-8?q?=20userEntity)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/payment/api/payment.controller.ts | 2 +- src/module/payment/data/payment.db.ts | 1 + src/module/payment/domain/payment.repository.ts | 2 ++ src/module/payment/domain/payment.service.ts | 4 ++-- src/module/payment/payment.module.ts | 15 ++++++++++----- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/module/payment/api/payment.controller.ts b/src/module/payment/api/payment.controller.ts index fd01693..1103681 100755 --- a/src/module/payment/api/payment.controller.ts +++ b/src/module/payment/api/payment.controller.ts @@ -9,7 +9,7 @@ import { RefundPaymentInfo } from '../domain/payment.model'; import { JwtAuthGuard } from "../../auth/auth.jwtAuthGuard"; //@UseGuards(AuthGuard) -@Controller('api/payment') +@Controller('/payment') export class PaymentController { constructor(private readonly paymentService: PaymentService) { diff --git a/src/module/payment/data/payment.db.ts b/src/module/payment/data/payment.db.ts index f098283..1ef00cb 100755 --- a/src/module/payment/data/payment.db.ts +++ b/src/module/payment/data/payment.db.ts @@ -16,6 +16,7 @@ export class PaymentRepositoryImpl implements PaymentRepository { // DB 주입 @InjectRepository(PaymentEntity) private PaymentDB: Repository, + @InjectRepository(UserEntity) private UserDB: Repository ){} diff --git a/src/module/payment/domain/payment.repository.ts b/src/module/payment/domain/payment.repository.ts index 7f7dc00..d7695cb 100755 --- a/src/module/payment/domain/payment.repository.ts +++ b/src/module/payment/domain/payment.repository.ts @@ -16,6 +16,7 @@ export class TestPaymentRepository implements PaymentRepository { async savePayment(paymentInfo: PaymentInfo): Promise { this.paymentInfos.push(paymentInfo); + return { paymentId: 1, userId : 1, @@ -38,6 +39,7 @@ export class TestPaymentRepository implements PaymentRepository { price : 10000 } } + async findUserPhoneNumber(userId: number): Promise { return '12341234'; } diff --git a/src/module/payment/domain/payment.service.ts b/src/module/payment/domain/payment.service.ts index 53e5bd4..8279e38 100755 --- a/src/module/payment/domain/payment.service.ts +++ b/src/module/payment/domain/payment.service.ts @@ -13,9 +13,9 @@ import { AlarmData } from 'src/module/alarm/alarm.service'; @Injectable() // 비즈니스 로직으로 분리 export class PaymentService { constructor( - @Inject('PaymentService') + @Inject('PaymentRepository') private readonly repository: PaymentRepository, - @Inject('PaymentService') + @Inject('AlarmService') private readonly alarmService: AlarmService, ) {} diff --git a/src/module/payment/payment.module.ts b/src/module/payment/payment.module.ts index bb46739..1a0a3f4 100755 --- a/src/module/payment/payment.module.ts +++ b/src/module/payment/payment.module.ts @@ -9,28 +9,33 @@ import { PaymentRepositoryImpl } from './data/payment.db'; import { AlarmService, AlarmServiceImpl } from '../alarm/alarm.service'; import { AlarmModule } from '../alarm/alarm.module'; import { AuthModule } from '../auth/auth.module'; +import { UserEntity } from '../user/data/user.entity'; @Module({ - imports: [AuthModule, TypeOrmModule.forFeature([PaymentEntity]), AlarmModule], + imports: [ + AuthModule, + TypeOrmModule.forFeature([PaymentEntity, UserEntity]), // PaymentEntityRepository 등록 + AlarmModule + ], controllers: [PaymentController], providers: [ PaymentService, { - provide: 'PaymentService', + provide: 'PaymentRepository', useClass: PaymentRepositoryImpl, }, { - provide: 'PaymentService', + provide: 'AlarmService', useClass: AlarmServiceImpl, }, ], exports: [ { - provide: 'PaymentService', + provide: 'PaymentRepository', useClass: PaymentRepositoryImpl, }, { - provide: 'PaymentService', + provide: 'AlarmService', useClass: AlarmServiceImpl, }, ], From a9124e24834faf97ecb61ab03b70d68435e4540b Mon Sep 17 00:00:00 2001 From: Sejin Park Date: Wed, 26 Jul 2023 17:44:35 +0900 Subject: [PATCH 2/3] =?UTF-8?q?db=EC=97=B0=EA=B2=B0=EC=9D=B4=20=EC=95=88?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EC=9D=B4=EC=9C=A0=20=ED=8C=8C=EC=95=85?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/module/payment/domain/payment.service.ts | 1 + src/module/payment/output/ormconfig.json | 2 +- src/module/payment/payment.module.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e18e83a..cfe43f3 100755 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "fastify-swagger": "^5.2.0", "moment": "^2.29.4", "moment-timezone": "^0.5.43", - "mysql2": "^3.4.1", + "mysql2": "^3.5.2", "nest-winston": "^1.9.3", "passport": "^0.6.0", "passport-jwt": "^4.0.1", diff --git a/src/module/payment/domain/payment.service.ts b/src/module/payment/domain/payment.service.ts index 8279e38..152540c 100755 --- a/src/module/payment/domain/payment.service.ts +++ b/src/module/payment/domain/payment.service.ts @@ -12,6 +12,7 @@ import { AlarmData } from 'src/module/alarm/alarm.service'; @Injectable() // 비즈니스 로직으로 분리 export class PaymentService { + constructor( @Inject('PaymentRepository') private readonly repository: PaymentRepository, diff --git a/src/module/payment/output/ormconfig.json b/src/module/payment/output/ormconfig.json index 55b8dbe..e0a473a 100755 --- a/src/module/payment/output/ormconfig.json +++ b/src/module/payment/output/ormconfig.json @@ -6,7 +6,7 @@ "port": 3306, "username": "root", "password": "skl035512!", - "database": "", + "database": "animalnest", "synchronize": false, "entities": ["entities/*.js"] } diff --git a/src/module/payment/payment.module.ts b/src/module/payment/payment.module.ts index 1a0a3f4..466ac23 100755 --- a/src/module/payment/payment.module.ts +++ b/src/module/payment/payment.module.ts @@ -14,7 +14,7 @@ import { UserEntity } from '../user/data/user.entity'; @Module({ imports: [ AuthModule, - TypeOrmModule.forFeature([PaymentEntity, UserEntity]), // PaymentEntityRepository 등록 + TypeOrmModule.forFeature([PaymentEntity,UserEntity]), AlarmModule ], controllers: [PaymentController], From b496f9a5fcc0a3525e451c11385c4b238aa69cbb Mon Sep 17 00:00:00 2001 From: Sejin Park Date: Wed, 26 Jul 2023 18:28:13 +0900 Subject: [PATCH 3/3] =?UTF-8?q?api=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20-=20=EA=B2=B0=EC=A0=9C=ED=95=98=EA=B8=B0,?= =?UTF-8?q?=20=EA=B2=B0=EC=A0=9C=20=EC=B7=A8=EC=86=8C=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/payment/data/payment.db.ts | 4 +++- src/module/payment/data/payment.entity.ts | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/module/payment/data/payment.db.ts b/src/module/payment/data/payment.db.ts index 1ef00cb..a6748cf 100755 --- a/src/module/payment/data/payment.db.ts +++ b/src/module/payment/data/payment.db.ts @@ -21,6 +21,8 @@ export class PaymentRepositoryImpl implements PaymentRepository { ){} async savePayment(paymentInfo: PaymentInfo): Promise { + + console.log("paymentInfo : " + paymentInfo); // user가 db에 존재하는지?? const user = await this.UserDB.findOne({ @@ -74,7 +76,7 @@ export class PaymentRepositoryImpl implements PaymentRepository { // entitiy -> domain const refundPaymentDomain: PaymentInfoForRefund = { - userId: payment.User.id, + userId: user.id, cardNum: payment.cardNum, endDate: payment.endDate, cvc: payment.cvc, diff --git a/src/module/payment/data/payment.entity.ts b/src/module/payment/data/payment.entity.ts index 7dddba7..c51baaf 100755 --- a/src/module/payment/data/payment.entity.ts +++ b/src/module/payment/data/payment.entity.ts @@ -9,16 +9,16 @@ export class PaymentEntity { @ManyToOne( () => UserEntity, (User) => User.PaymentEntity ) @JoinColumn([{name: 'userId', referencedColumnName: 'id'}]) - User: UserEntity; + User: UserEntity | null; // nullable로 변경 //@JoinColumn([{ name: 'userId', referencedColumnName: 'id' }]) - @Column('int', { name: 'card_num' }) + @Column('int', { name: 'card_num', nullable: true }) cardNum: number; - @Column('varchar', { name: 'end_date', length: 45 }) + @Column('varchar', { name: 'end_date', length: 45, nullable: true }) endDate: string; - @Column('int', { name: 'cvc' }) + @Column('int', { name: 'cvc', nullable: true }) cvc: number; @Column('enum', { @@ -33,6 +33,7 @@ export class PaymentEntity { 'hyundai', 'nonghyup', ], + nullable: true }) cardCompany: | 'kookmin' @@ -44,9 +45,9 @@ export class PaymentEntity { | 'hyundai' | 'nonghyup'; - @Column('int', { name: 'price' }) + @Column('int', { name: 'price', nullable: true }) price: number; - @Column("boolean", { name: "is_refund" }) + @Column("boolean", { name: "is_refund", nullable: false, default: 0 }) isRefund: boolean; }