diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index e7d2ceb..b4c2dc0 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -40,7 +40,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); } // 일반유저(내가) 구매한 작품 조회 @@ -49,7 +55,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 2b68bdd..7ee462a 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; 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'; @@ -90,17 +90,26 @@ export class ArtService { } // 미대생이 판매중인 작품 조회 - async findAction({ currentUser }) { + async findAuction({ currentUser }) { const art = await this.artRepository.find({ - 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'], 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 6dd753d..e85eae4 100644 --- a/ars/src/apis/art/entities/art.entity.ts +++ b/ars/src/apis/art/entities/art.entity.ts @@ -58,6 +58,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/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 a29113b..cb1a7b1 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, - chargs_amount: 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/apis/user/user.resolver.ts b/ars/src/apis/user/user.resolver.ts index 81654fc..3e8f69a 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(() => String) + 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..d463cda 100644 --- a/ars/src/apis/user/user.service.ts +++ b/ars/src/apis/user/user.service.ts @@ -26,6 +26,26 @@ export class UserService { return await this.userRepository.findOne({ email }); } + async findUserEmail({ phoneNum }) { + const user = await this.userRepository.findOne({ phoneNum }); + console.log(user.email); + let newEmail = ''; + let frontEmail = user.email.split('@')[0]; + let backEmail = user.email.split('@')[1]; + if (user) { + 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('존재하지 않은 회원입니다.'); + } + } + async checkNickname(nickname) { const user = await this.userRepository.findOne({ nickname }); if (user) { diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index fdc80fe..cf1a78d 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -52,6 +52,7 @@ type Art { deletedAt: DateTime! deadline: DateTime! is_soldout: Boolean! + deletedAt: DateTime! user: User! payment: Payment! tag1: String! @@ -85,6 +86,7 @@ type History { id: String! createdAt: DateTime! point: Int! + balance: Int! user: User! pointTransaction: PointTransaction payment: Payment 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", }, } );