From 09db5b34bd00783d6dd4189694e7e3b730e77a01 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: Mon, 4 Apr 2022 00:08:44 +0900 Subject: [PATCH] =?UTF-8?q?[#124]feat:=20=EC=9D=BC=EB=B0=98=EC=9C=A0?= =?UTF-8?q?=EC=A0=80(=EB=82=B4=EA=B0=80)=20=EA=B5=AC=EB=A7=A4=ED=95=9C=20?= =?UTF-8?q?=EC=9E=91=ED=92=88=20=EC=A1=B0=ED=9A=8C=20(fetchTransactionComp?= =?UTF-8?q?letedArts=20API)=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/art/art.resolver.ts | 3 +- ars/src/apis/art/art.service.ts | 24 ++++-- ars/src/apis/art/entities/art.entity.ts | 2 +- ars/src/apis/art/entities/likeArt.entity.ts | 5 +- .../apis/payment/entities/payment.entity.ts | 4 +- ars/src/apis/user/entities/user.entity.ts | 13 +++- ars/src/common/graphql/schema.gql | 73 ++++++++++--------- 7 files changed, 75 insertions(+), 49 deletions(-) diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index e3b9287..5e9621f 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -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); @@ -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); diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 00aacb8..0a1b7e4 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -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'; @@ -15,6 +17,12 @@ export class ArtService { @InjectRepository(ArtImage) private readonly artImageRepository: Repository, + @InjectRepository(User) + private readonly userRepository: Repository, + + @InjectRepository(Payment) + private readonly paymentRepository: Repository, + private readonly connection: Connection, ) {} @@ -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; } diff --git a/ars/src/apis/art/entities/art.entity.ts b/ars/src/apis/art/entities/art.entity.ts index 87b0acd..262bba8 100644 --- a/ars/src/apis/art/entities/art.entity.ts +++ b/ars/src/apis/art/entities/art.entity.ts @@ -67,7 +67,7 @@ export class Art { @Field(() => User) user: User; - @OneToOne(() => Payment) + @OneToOne(() => Payment, (payment) => payment.art) @Field(() => Payment) payment: Payment; diff --git a/ars/src/apis/art/entities/likeArt.entity.ts b/ars/src/apis/art/entities/likeArt.entity.ts index ef19738..6828094 100644 --- a/ars/src/apis/art/entities/likeArt.entity.ts +++ b/ars/src/apis/art/entities/likeArt.entity.ts @@ -1,4 +1,4 @@ -import { ObjectType } from '@nestjs/graphql'; +import { Field, ObjectType } from '@nestjs/graphql'; import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { Art } from './art.entity'; @@ -6,11 +6,14 @@ import { Art } from './art.entity'; @ObjectType() export class LikeArt { @PrimaryGeneratedColumn() + @Field(() => String) id: string; @Column() + @Field(() => String) userId: string; @ManyToOne(() => Art, { eager: true }) + @Field(() => Art) art: Art; } diff --git a/ars/src/apis/payment/entities/payment.entity.ts b/ars/src/apis/payment/entities/payment.entity.ts index 47648ee..626e83d 100644 --- a/ars/src/apis/payment/entities/payment.entity.ts +++ b/ars/src/apis/payment/entities/payment.entity.ts @@ -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; } diff --git a/ars/src/apis/user/entities/user.entity.ts b/ars/src/apis/user/entities/user.entity.ts index 2d62c35..96024de 100644 --- a/ars/src/apis/user/entities/user.entity.ts +++ b/ars/src/apis/user/entities/user.entity.ts @@ -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() @@ -44,4 +51,8 @@ export class User { @OneToOne(() => Profile) @Field(() => Profile, { nullable: true }) profile?: Profile; + + @OneToMany(() => Payment, (payment) => payment.user) + @Field(() => Payment) + payment: Payment; } diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 4cc2639..a389f3e 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -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! @@ -13,6 +47,7 @@ type User { is_artist: Boolean! college: String! profile: Profile + payment: Payment! } type Profile { @@ -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! @@ -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!]! @@ -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!