From 9cd38f594664236cd9432a843fe6170dbaee45c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=8B=A4=EC=8A=AC?= <95472052+Daseul1@users.noreply.github.com> Date: Tue, 29 Mar 2022 14:44:01 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[#71]feat:=20history=20table=20balance=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/history/entities/history.entity.ts | 4 ++++ .../pointTransaction.service.ts | 21 +++++++++---------- ars/src/app.module.ts | 2 +- ars/src/common/graphql/schema.gql | 1 + ars/src/main.ts | 8 +++---- frontend/payment.html | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/ars/src/apis/history/entities/history.entity.ts b/ars/src/apis/history/entities/history.entity.ts index cea69a4..b18be65 100644 --- a/ars/src/apis/history/entities/history.entity.ts +++ b/ars/src/apis/history/entities/history.entity.ts @@ -26,6 +26,10 @@ export class History { @Field(() => Int) point: number; + @Column() + @Field(() => Int) + balance: number; + @ManyToOne(() => User, { eager: true }) @Field(() => User) user: User; diff --git a/ars/src/apis/pointTransaction/pointTransaction.service.ts b/ars/src/apis/pointTransaction/pointTransaction.service.ts index a94df45..3746ad6 100644 --- a/ars/src/apis/pointTransaction/pointTransaction.service.ts +++ b/ars/src/apis/pointTransaction/pointTransaction.service.ts @@ -29,7 +29,6 @@ export class PointTransactionServive { // 현재 로그인한 유저가 포인트 내역 조회 async findOne(userId: string) { - console.log('💛'); return await this.pointTransactionRepository.findOne({ where: { user: userId, @@ -65,33 +64,33 @@ export class PointTransactionServive { { id: currentUser.id }, { lock: { mode: 'pessimistic_write' } }, ); - console.log('!!!!'); + // pointTransaction 테이블에 거래기록 생성 const pointTransaction = await queryRunner.manager.save( PointTransaction, { impUid: impUid, - point: charge_amount, + charge_amount: charge_amount, user: user, status: POINTTRANSACTION_STATUS_ENUM.PAYMENT, }, ); - console.log(pointTransaction); + // 유저 누적 포인트 업데이트 + const updatedUser = this.userRepository.create({ + ...user, + point: user.point + charge_amount, + }); + await queryRunner.manager.save(updatedUser); + // history 테이블에 거래기록 생성 const pointTransactionH = this.historyRepository.create({ point: charge_amount, + balance: updatedUser.point, user: user, pointTransaction: pointTransaction, }); await queryRunner.manager.save(History, pointTransactionH); - // 유저 누적 포인트 업데이트 - const updatedUser = this.userRepository.create({ - ...user, - point: user.point + charge_amount, - }); - - await queryRunner.manager.save(updatedUser); await queryRunner.commitTransaction(); return pointTransaction; diff --git a/ars/src/app.module.ts b/ars/src/app.module.ts index 65ba8a7..31d2eb6 100644 --- a/ars/src/app.module.ts +++ b/ars/src/app.module.ts @@ -35,7 +35,7 @@ import { PaymentModule } from './apis/payment/payment.module'; driver: ApolloDriver, autoSchemaFile: 'src/common/graphql/schema.gql', context: ({ req, res }) => ({ req, res }), - cors: { origin: 'http://localhost:3000', credential: true }, + // cors: { origin: 'http://localhost:3000', credential: true }, }), TypeOrmModule.forRoot({ type: 'mysql', diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index c513461..d5db752 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -84,6 +84,7 @@ type History { id: String! createdAt: DateTime! point: Int! + balance: Int! user: User! pointTransaction: PointTransaction payment: Payment diff --git a/ars/src/main.ts b/ars/src/main.ts index f4f6b1f..7e5d94a 100644 --- a/ars/src/main.ts +++ b/ars/src/main.ts @@ -5,10 +5,10 @@ import { graphqlUploadExpress } from 'graphql-upload'; async function bootstrap() { const app = await NestFactory.create(AppModule); - app.enableCors({ - origin: 'http://localhost:3000', - credentials: true, - }); + // app.enableCors({ + // origin: 'http://localhost:3000', + // credentials: true, + // }); app.use(graphqlUploadExpress()); await app.listen(3000); } diff --git a/frontend/payment.html b/frontend/payment.html index 97150a8..e098a8b 100644 --- a/frontend/payment.html +++ b/frontend/payment.html @@ -57,7 +57,7 @@ { headers: { Authorization: - "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImNAYy5jb20iLCJzdWIiOiI0Yjg1YTg1YS1kNjQ5LTQwZGEtOTkyNy1lYTlhZThlODRkZGMiLCJpYXQiOjE2NDgzNjk3ODEsImV4cCI6MTY0ODM3MzM4MX0.fpB8WZxpIOZ2U3KDDMhJ70BfKpXKnuY1vRPF272BY3g", + "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFhYUBhLmEiLCJzdWIiOiJjNDlhNjc1MS1jMzA3LTQyZmYtYWE5MS1kZDFmYzA4MGNjMzMiLCJpYXQiOjE2NDg1MzIzNDcsImV4cCI6MTY0ODUzNTk0N30.4dRtuBTpWbQbYM6K1aLmcEoHLRKDiuxAQ_hV82J9wVA", }, } ); From 0d42659b8d8d70dccc7b103fd707a7b8c785aefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=8B=A4=EC=8A=AC?= <95472052+Daseul1@users.noreply.github.com> Date: Tue, 29 Mar 2022 16:07:42 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[#73]feat:=20=EC=95=84=EC=9D=B4=EB=94=94?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/user/user.resolver.ts | 5 +++++ ars/src/apis/user/user.service.ts | 10 ++++++++++ ars/src/app.module.ts | 2 +- ars/src/common/graphql/schema.gql | 1 + ars/src/main.ts | 8 ++++---- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ars/src/apis/user/user.resolver.ts b/ars/src/apis/user/user.resolver.ts index 81654fc..de44c12 100644 --- a/ars/src/apis/user/user.resolver.ts +++ b/ars/src/apis/user/user.resolver.ts @@ -17,6 +17,11 @@ export class UserResolver { return await this.userService.findOne(currentUser.email); } + @Query(() => User) + async findUserEmail(@Args('phoneNum') phoneNum: string) { + return await this.userService.findUserEmail({ phoneNum }); + } + @Mutation(() => User) async createUser(@Args('createUserInput') createUserInput: CreateUserInput) { const { password, ...rest } = createUserInput; diff --git a/ars/src/apis/user/user.service.ts b/ars/src/apis/user/user.service.ts index a40ea75..8fa9259 100644 --- a/ars/src/apis/user/user.service.ts +++ b/ars/src/apis/user/user.service.ts @@ -26,6 +26,16 @@ export class UserService { return await this.userRepository.findOne({ email }); } + async findUserEmail({ phoneNum }) { + const user = await this.userRepository.findOne({ phoneNum }); + console.log(user); + if (user) { + return await this.userRepository.findOne({ email: user.email }); + } else { + throw new Error('존재하지 않은 회원입니다.'); + } + } + async checkNickname(nickname) { const user = await this.userRepository.findOne({ nickname }); if (user) { diff --git a/ars/src/app.module.ts b/ars/src/app.module.ts index 31d2eb6..65ba8a7 100644 --- a/ars/src/app.module.ts +++ b/ars/src/app.module.ts @@ -35,7 +35,7 @@ import { PaymentModule } from './apis/payment/payment.module'; driver: ApolloDriver, autoSchemaFile: 'src/common/graphql/schema.gql', context: ({ req, res }) => ({ req, res }), - // cors: { origin: 'http://localhost:3000', credential: true }, + cors: { origin: 'http://localhost:3000', credential: true }, }), TypeOrmModule.forRoot({ type: 'mysql', diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index d5db752..9846b1b 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -130,6 +130,7 @@ type Query { fetchHistory(page: Float!): [History!]! fetchProfile: Profile! fetchUser: User! + findUserEmail(phoneNum: String!): User! fetchPointTransactions: [PointTransaction!]! } diff --git a/ars/src/main.ts b/ars/src/main.ts index 7e5d94a..f4f6b1f 100644 --- a/ars/src/main.ts +++ b/ars/src/main.ts @@ -5,10 +5,10 @@ import { graphqlUploadExpress } from 'graphql-upload'; async function bootstrap() { const app = await NestFactory.create(AppModule); - // app.enableCors({ - // origin: 'http://localhost:3000', - // credentials: true, - // }); + app.enableCors({ + origin: 'http://localhost:3000', + credentials: true, + }); app.use(graphqlUploadExpress()); await app.listen(3000); } From 2a7fc0708d2813d4559a9f03079e033bbbf0f1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=8B=A4=EC=8A=AC?= <95472052+Daseul1@users.noreply.github.com> Date: Tue, 29 Mar 2022 16:22:04 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[#75]feat:=20art=EC=97=90=20softdelete?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=84=A0=ED=96=89=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/art/art.service.ts | 2 ++ ars/src/apis/art/entities/art.entity.ts | 5 +++++ ars/src/common/graphql/schema.gql | 1 + 3 files changed, 8 insertions(+) diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 9608ddc..48e6acf 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -97,6 +97,7 @@ export class ArtService { // 미대생이 판매중인 작품 조회 async findAction({ currentUser }) { const art = await this.artRepository.find({ + withDeleted: true, relations: ['user'], where: { user: currentUser.id, is_soldout: false }, }); @@ -106,6 +107,7 @@ export class ArtService { // 일반유저(내가) 구매한 작품 조회 async findcompleteAction({ currentUser }) { const art = await this.artRepository.find({ + withDeleted: true, relations: ['user'], where: { user: currentUser.id, is_soldout: true }, }); diff --git a/ars/src/apis/art/entities/art.entity.ts b/ars/src/apis/art/entities/art.entity.ts index 9b9c134..4f9a271 100644 --- a/ars/src/apis/art/entities/art.entity.ts +++ b/ars/src/apis/art/entities/art.entity.ts @@ -4,6 +4,7 @@ import { User } from 'src/apis/user/entities/user.entity'; import { Column, CreateDateColumn, + DeleteDateColumn, Entity, ManyToOne, OneToOne, @@ -53,6 +54,10 @@ export class Art { @Field(() => Boolean) is_soldout: boolean; + @DeleteDateColumn() + @Field(() => Date) + deletedAt: Date; + @ManyToOne(() => User, { eager: true }) @Field(() => User) user: User; diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 9846b1b..f3ad1cb 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -51,6 +51,7 @@ type Art { createdAt: DateTime! deadline: String! is_soldout: Boolean! + deletedAt: DateTime! user: User! payment: Payment! tag1: String! From 94d882943d0b3e6bce0917cfec7c75b76349c60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=8B=A4=EC=8A=AC?= <95472052+Daseul1@users.noreply.github.com> Date: Tue, 29 Mar 2022 20:48:58 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[#77]feat:=EC=95=84=EC=9D=B4=EB=94=94?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0=20*=20=ED=91=9C=EC=8B=9C=20,=20=EB=AF=B8?= =?UTF-8?q?=EB=8C=80=EC=83=9D=20=EB=A7=88=EA=B0=90=EB=90=9C=20=EC=9E=91?= =?UTF-8?q?=ED=92=88=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/art/art.resolver.ts | 10 ++++++++-- ars/src/apis/art/art.service.ts | 17 ++++++++++++----- ars/src/apis/user/user.resolver.ts | 2 +- ars/src/apis/user/user.service.ts | 14 ++++++++++++-- ars/src/common/graphql/schema.gql | 2 +- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index ac3e713..bcd6f9d 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -41,7 +41,13 @@ export class ArtResolver { @UseGuards(GqlAuthAccessGuard) @Query(() => [Art]) async fetchAuctionArts(@CurrentUser() currentUser: ICurrentUser) { - return await this.artService.findAction({ currentUser }); + return await this.artService.findAuction({ currentUser }); + } + + // 미대생 마감된 작품 조회 + @UseGuards(GqlAuthAccessGuard) + async fetchTimedOutArt(@CurrentUser() currentUser: ICurrentUser) { + return await this.artService.fetchTimedOutArt(currentUser); } // 일반유저(내가) 구매한 작품 조회 @@ -50,7 +56,7 @@ export class ArtResolver { async fetchtransactioncompletedArts( @CurrentUser() currentUser: ICurrentUser, ) { - return await this.artService.findcompleteAction({ currentUser }); + return await this.artService.findcompleteAuction({ currentUser }); } @UseGuards(GqlAuthAccessGuard) diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 48e6acf..51a3f1d 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -1,7 +1,7 @@ import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common'; import { Cache } from 'cache-manager'; import { InjectRepository } from '@nestjs/typeorm'; -import { Connection, getRepository, MoreThan, Repository } from 'typeorm'; +import { Connection, getRepository, MoreThan, Not, Repository } from 'typeorm'; import { ArtImage } from '../artImage/entities/artImage.entity'; import { Art } from './entities/art.entity'; @@ -95,17 +95,24 @@ export class ArtService { } // 미대생이 판매중인 작품 조회 - async findAction({ currentUser }) { + async findAuction({ currentUser }) { const art = await this.artRepository.find({ - withDeleted: true, - relations: ['user'], where: { user: currentUser.id, is_soldout: false }, }); return art; } + // 미대생 마감된 작품 조회 + async fetchTimedOutArt(currentUser) { + const art = await this.artRepository.find({ + withDeleted: true, + where: { user: currentUser.id, deletedAt: Not(null) }, + }); + return art; + } + // 일반유저(내가) 구매한 작품 조회 - async findcompleteAction({ currentUser }) { + async findcompleteAuction({ currentUser }) { const art = await this.artRepository.find({ withDeleted: true, relations: ['user'], diff --git a/ars/src/apis/user/user.resolver.ts b/ars/src/apis/user/user.resolver.ts index de44c12..3e8f69a 100644 --- a/ars/src/apis/user/user.resolver.ts +++ b/ars/src/apis/user/user.resolver.ts @@ -17,7 +17,7 @@ export class UserResolver { return await this.userService.findOne(currentUser.email); } - @Query(() => User) + @Query(() => String) async findUserEmail(@Args('phoneNum') phoneNum: string) { return await this.userService.findUserEmail({ phoneNum }); } diff --git a/ars/src/apis/user/user.service.ts b/ars/src/apis/user/user.service.ts index 8fa9259..d463cda 100644 --- a/ars/src/apis/user/user.service.ts +++ b/ars/src/apis/user/user.service.ts @@ -28,9 +28,19 @@ export class UserService { async findUserEmail({ phoneNum }) { const user = await this.userRepository.findOne({ phoneNum }); - console.log(user); + console.log(user.email); + let newEmail = ''; + let frontEmail = user.email.split('@')[0]; + let backEmail = user.email.split('@')[1]; if (user) { - return await this.userRepository.findOne({ email: user.email }); + if (frontEmail.length > 3) { + frontEmail = frontEmail.slice(-3).padStart(frontEmail.length, '*'); + newEmail = frontEmail + '@' + backEmail; + } else if (frontEmail.length <= 3) { + frontEmail = ''.padStart(frontEmail.length, '*'); + newEmail = frontEmail + '@' + backEmail; + } + return newEmail; } else { throw new Error('존재하지 않은 회원입니다.'); } diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index f3ad1cb..0a1dae3 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -131,7 +131,7 @@ type Query { fetchHistory(page: Float!): [History!]! fetchProfile: Profile! fetchUser: User! - findUserEmail(phoneNum: String!): User! + findUserEmail(phoneNum: String!): String! fetchPointTransactions: [PointTransaction!]! }