Skip to content

Commit

Permalink
Merge pull request #127 from Daseul1/feat/#124
Browse files Browse the repository at this point in the history
[#124]feat: 일반유저(내가) 구매한 작품 조회 (fetchTransactionCompletedArts API) 수정
  • Loading branch information
Daseul1 committed Apr 3, 2022
2 parents d3ee7bb + 6c4b83f commit cfc489c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 50 deletions.
3 changes: 2 additions & 1 deletion ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class ArtResolver {
@UseGuards(GqlAuthAccessGuard)
@Query(() => [Art])
async fetchTransactionCompletedArts(
@Args('page') page: number,
@Args('page', { nullable: true }) page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.findcompleteAuction({ currentUser }, page);
Expand Down Expand Up @@ -317,6 +317,7 @@ export class ArtResolver {
@Mutation(() => Boolean)
async addLikeArt(
@Args('artId') artId: string,
@Args('likeId', { nullable: true }) likeId: string,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.likeArtService.like(artId, currentUser.id);
Expand Down
24 changes: 17 additions & 7 deletions ars/src/apis/art/art.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, IsNull, MoreThan, Not, Repository } from 'typeorm';
import { Connection, getRepository, IsNull, Not, Repository } from 'typeorm';
import { ArtImage } from '../artImage/entities/artImage.entity';
import { Engage } from '../engage/entities/engage.entity';
import { Payment } from '../payment/entities/payment.entity';
import { User } from '../user/entities/user.entity';
import { Art } from './entities/art.entity';
import { LikeArt } from './entities/likeArt.entity';

Expand All @@ -15,6 +17,12 @@ export class ArtService {
@InjectRepository(ArtImage)
private readonly artImageRepository: Repository<ArtImage>,

@InjectRepository(User)
private readonly userRepository: Repository<User>,

@InjectRepository(Payment)
private readonly paymentRepository: Repository<Payment>,

private readonly connection: Connection,
) {}

Expand Down Expand Up @@ -115,12 +123,14 @@ export class ArtService {

// 일반유저(내가) 구매한 작품 조회
async findcompleteAuction({ currentUser }, page) {
const art = await this.artRepository.find({
withDeleted: true,
take: 10,
skip: 10 * (page - 1),
where: { user: currentUser.id, is_soldout: true },
});
const art = await getRepository(Art)
.createQueryBuilder('art')
.leftJoinAndSelect('art.payment', 'payment')
.leftJoinAndSelect('payment.user', 'user')
.where('user.id =:id', { id: currentUser.id })
.withDeleted()
.getMany();
console.log('***********', art);
return art;
}

Expand Down
2 changes: 1 addition & 1 deletion ars/src/apis/art/entities/art.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Art {
@Field(() => User)
user: User;

@OneToOne(() => Payment)
@OneToOne(() => Payment, (payment) => payment.art)
@Field(() => Payment)
payment: Payment;

Expand Down
5 changes: 3 additions & 2 deletions ars/src/apis/art/entities/likeArt.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { Field, ObjectType } from '@nestjs/graphql';
import { User } from 'src/apis/user/entities/user.entity';
import {
Expand All @@ -18,8 +17,10 @@ export class LikeArt {
id: string;

@Column()
@Field(() => String)
userId: string;

@ManyToOne(() => Art)
@ManyToOne(() => Art, { eager: true })
@Field(() => Art)
art: Art;
}
4 changes: 2 additions & 2 deletions ars/src/apis/payment/entities/payment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export class Payment {
amount: number;

@JoinColumn()
@OneToOne(() => Art)
@OneToOne(() => Art, (art) => art.payment)
@Field(() => Art)
art: Art;

@ManyToOne(() => User, { eager: true })
@ManyToOne(() => User, (user) => user.payment, { eager: true })
@Field(() => User)
user: User;
}
13 changes: 12 additions & 1 deletion ars/src/apis/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import {
Column,
Entity,
OneToMany,
OneToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Field, Int, ObjectType } from '@nestjs/graphql';
import { Profile } from 'src/apis/profile/entities/profile.entity';
import { Payment } from 'src/apis/payment/entities/payment.entity';

@Entity()
@ObjectType()
Expand Down Expand Up @@ -44,4 +51,8 @@ export class User {
@OneToOne(() => Profile)
@Field(() => Profile, { nullable: true })
profile?: Profile;

@OneToMany(() => Payment, (payment) => payment.user)
@Field(() => Payment)
payment: Payment;
}
73 changes: 37 additions & 36 deletions ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

type Art {
id: String!
title: String!
description: String!
start_price: Int!
instant_bid: Int!
price: Int!
thumbnail: String!
createdAt: DateTime!
deletedAt: DateTime!
deadline: String!
is_soldout: Boolean!
updatedAt: DateTime!
user: User!
payment: Payment!
tag1: String!
tag2: String
tag3: String
tag4: String
}

"""
A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format.
"""
scalar DateTime

type Payment {
id: String!
createdAt: DateTime!
amount: Int!
art: Art!
user: User!
}

type User {
id: String!
name: String!
Expand All @@ -13,6 +47,7 @@ type User {
is_artist: Boolean!
college: String!
profile: Profile
payment: Payment!
}

type Profile {
Expand All @@ -27,40 +62,6 @@ type Token {
accessToken: String!
}

type Payment {
id: String!
createdAt: DateTime!
amount: Int!
art: Art!
user: User!
}

"""
A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format.
"""
scalar DateTime

type Art {
id: String!
title: String!
description: String!
start_price: Int!
instant_bid: Int!
price: Int!
thumbnail: String!
createdAt: DateTime!
deletedAt: DateTime!
deadline: String!
is_soldout: Boolean!
updatedAt: DateTime!
user: User!
payment: Payment!
tag1: String!
tag2: String
tag3: String
tag4: String
}

type ArtImage {
id: String!
url: String!
Expand Down Expand Up @@ -145,7 +146,7 @@ type Query {
fetchAuctionArtsCount: Float!
fetchAuctionArts(page: Float!): [Art!]!
fetchTimedOutArt(page: Float!): [Art!]!
fetchTransactionCompletedArts(page: Float!): [Art!]!
fetchTransactionCompletedArts(page: Float): [Art!]!
fetchEngaging(page: Float!): [Engage!]!
fetchArtistWorks(artId: String!): [Art!]!
fetchLikeArt(page: Float): [Art!]!
Expand All @@ -170,7 +171,7 @@ type Query {
type Mutation {
createArt(createArtInput: CreateArtInput!): Art!
uploadArtImage(files: [Upload!]!): [String!]!
addLikeArt(artId: String!): Boolean!
addLikeArt(artId: String!, likeId: String): Boolean!
login(email: String!, password: String!): Token!
restoreAccessToken: Token!
logout: String!
Expand Down

0 comments on commit cfc489c

Please sign in to comment.