Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#70
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Mar 29, 2022
2 parents a8d9167 + 591eb96 commit 74f5a58
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 18 deletions.
10 changes: 8 additions & 2 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// 일반유저(내가) 구매한 작품 조회
Expand All @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions ars/src/apis/art/art.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 },
});
Expand Down
4 changes: 4 additions & 0 deletions ars/src/apis/art/entities/art.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions ars/src/apis/history/entities/history.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class History {
@Field(() => Int)
point: number;

@Column()
@Field(() => Int)
balance: number;

@ManyToOne(() => User, { eager: true })
@Field(() => User)
user: User;
Expand Down
21 changes: 10 additions & 11 deletions ars/src/apis/pointTransaction/pointTransaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class PointTransactionServive {

// 현재 로그인한 유저가 포인트 내역 조회
async findOne(userId: string) {
console.log('💛');
return await this.pointTransactionRepository.findOne({
where: {
user: userId,
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions ars/src/apis/user/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions ars/src/apis/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Art {
deletedAt: DateTime!
deadline: DateTime!
is_soldout: Boolean!
deletedAt: DateTime!
user: User!
payment: Payment!
tag1: String!
Expand Down Expand Up @@ -85,6 +86,7 @@ type History {
id: String!
createdAt: DateTime!
point: Int!
balance: Int!
user: User!
pointTransaction: PointTransaction
payment: Payment
Expand Down
2 changes: 1 addition & 1 deletion frontend/payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{
headers: {
Authorization:
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImNAYy5jb20iLCJzdWIiOiI0Yjg1YTg1YS1kNjQ5LTQwZGEtOTkyNy1lYTlhZThlODRkZGMiLCJpYXQiOjE2NDgzNjk3ODEsImV4cCI6MTY0ODM3MzM4MX0.fpB8WZxpIOZ2U3KDDMhJ70BfKpXKnuY1vRPF272BY3g",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFhYUBhLmEiLCJzdWIiOiJjNDlhNjc1MS1jMzA3LTQyZmYtYWE5MS1kZDFmYzA4MGNjMzMiLCJpYXQiOjE2NDg1MzIzNDcsImV4cCI6MTY0ODUzNTk0N30.4dRtuBTpWbQbYM6K1aLmcEoHLRKDiuxAQ_hV82J9wVA",
},
}
);
Expand Down

0 comments on commit 74f5a58

Please sign in to comment.