Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/add_logger_st…
Browse files Browse the repository at this point in the history
…ack_trace

# Conflicts:
#	src/module/payment/data/payment.db.ts
#	src/module/payment/data/payment.entity.ts
  • Loading branch information
KJJDSA committed Jul 26, 2023
2 parents 67dda92 + 07f0d3e commit 8d14033
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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",
Expand Down
2 changes: 1 addition & 1 deletion src/module/payment/api/payment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
49 changes: 27 additions & 22 deletions src/module/payment/data/payment.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ import { UserEntity } from 'src/module/user/data/user.entity';
// 실제 DB
@Injectable()
export class PaymentRepositoryImpl implements PaymentRepository {
constructor(
// DB 주입
@InjectRepository(PaymentEntity)
private PaymentDB: Repository<PaymentEntity>,
private UserDB: Repository<UserEntity>,
) {}

async savePayment(paymentInfo: PaymentInfo): Promise<Payment> {
// user가 db에 존재하는지??
const user = await this.UserDB.findOne({
where: { id: paymentInfo.userId },
});
if (user === null) throw new InvalidPaymentInfoError('유저');

constructor(
// DB 주입
@InjectRepository(PaymentEntity)
private PaymentDB: Repository<PaymentEntity>,
@InjectRepository(UserEntity)
private UserDB: Repository<UserEntity>
){}

async savePayment(paymentInfo: PaymentInfo): Promise<Payment> {

console.log("paymentInfo : " + paymentInfo);

// user가 db에 존재하는지??
const user = await this.UserDB.findOne({
where: { id: paymentInfo.userId },
});
if (user === null) throw new InvalidPaymentInfoError('유저');

// model -> entitiy
const entity = this.PaymentDB.create({
Expand Down Expand Up @@ -73,15 +78,15 @@ export class PaymentRepositoryImpl implements PaymentRepository {
payment.isRefund = true; // 원하는 칼럼을 true로 변경
await this.PaymentDB.save(payment); // 변경 내용을 저장

// entitiy -> domain
const refundPaymentDomain: PaymentInfoForRefund = {
userId: payment.User.id,
cardNum: payment.cardNum,
endDate: payment.endDate,
cvc: payment.cvc,
cardCompany: payment.cardCompany,
price: payment.price,
};
// entitiy -> domain
const refundPaymentDomain: PaymentInfoForRefund = {
userId: user.id,
cardNum: payment.cardNum,
endDate: payment.endDate,
cvc: payment.cvc,
cardCompany: payment.cardCompany,
price: payment.price,
};

return refundPaymentDomain;
}
Expand Down
20 changes: 11 additions & 9 deletions src/module/payment/data/payment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ export class PaymentEntity {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;

@ManyToOne(() => UserEntity, (User) => User.PaymentEntity)
@JoinColumn([{ name: 'userId', referencedColumnName: 'id' }])
User: UserEntity;
@ManyToOne( () => UserEntity, (User) => User.PaymentEntity )
@JoinColumn([{name: 'userId', referencedColumnName: 'id'}])

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', {
Expand All @@ -38,6 +39,7 @@ export class PaymentEntity {
'hyundai',
'nonghyup',
],
nullable: true
})
cardCompany:
| 'kookmin'
Expand All @@ -49,9 +51,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;
}
2 changes: 2 additions & 0 deletions src/module/payment/domain/payment.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class TestPaymentRepository implements PaymentRepository {
async savePayment(paymentInfo: PaymentInfo): Promise<Payment> {
this.paymentInfos.push(paymentInfo);


return {
paymentId: 1,
userId: 1,
Expand All @@ -38,6 +39,7 @@ export class TestPaymentRepository implements PaymentRepository {
price: 10000,
};
}

async findUserPhoneNumber(userId: number): Promise<string> {
return '12341234';
}
Expand Down
5 changes: 3 additions & 2 deletions src/module/payment/domain/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ 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,
) {}

Expand Down
2 changes: 1 addition & 1 deletion src/module/payment/output/ormconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"port": 3306,
"username": "root",
"password": "skl035512!",
"database": "",
"database": "animalnest",
"synchronize": false,
"entities": ["entities/*.js"]
}
Expand Down
15 changes: 10 additions & 5 deletions src/module/payment/payment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
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,
},
],
Expand Down

0 comments on commit 8d14033

Please sign in to comment.