From 0f87e3e0ef946f0eb40a6aa6c4f2267bc9ee380f Mon Sep 17 00:00:00 2001 From: Arios67 Date: Thu, 31 Mar 2022 15:14:44 +0900 Subject: [PATCH] =?UTF-8?q?[#95]feat:=20mypage=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/art/art.resolver.ts | 31 ++++++++++++ ars/src/apis/art/art.service.ts | 64 ++++++++++++++++++++++++ ars/src/apis/auth/auth.service.ts | 1 - ars/src/apis/history/history.resolver.ts | 6 +++ ars/src/apis/history/history.service.ts | 5 ++ ars/src/common/graphql/schema.gql | 10 +++- 6 files changed, 114 insertions(+), 3 deletions(-) diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index 2860027..47a53cd 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -38,6 +38,37 @@ export class ArtResolver { async fetchArtImages(@Args('artId') artId: string) { return await this.artService.findImages({ artId }); } + /////////////////////////////////////////////////////////////////////////// + @UseGuards(GqlAuthAccessGuard) + @Query(() => Number) + async fetchEngageCount(@CurrentUser() currentUser: ICurrentUser) { + return await this.artService.countEngage(currentUser.id); + } + + @UseGuards(GqlAuthAccessGuard) + @Query(() => Number) + async fetchLikeArtCount(@CurrentUser() currentUser: ICurrentUser) { + return await this.artService.countLikeArt(currentUser.id); + } + + @UseGuards(GqlAuthAccessGuard) + @Query(() => Number) + async fetchSoldoutArtsCount(@CurrentUser() currentUser: ICurrentUser) { + return await this.artService.countComletedAuctionArts(currentUser.id); + } + + @UseGuards(GqlAuthAccessGuard) + @Query(() => Number) + async fetchTimedOutArtsCount(@CurrentUser() currentUser: ICurrentUser) { + return await this.artService.countTimedoutArts(currentUser.id); + } + + @UseGuards(GqlAuthAccessGuard) + @Query(() => Number) + async fetchAuctionArtsCount(@CurrentUser() currentUser: ICurrentUser) { + return await this.artService.countAuctionArts(currentUser.id); + } + ////////////////////////////////////////////////////////////////////////// // 미대생이 판매중인 작품 조회 @UseGuards(GqlAuthAccessGuard) diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index c7bfe17..24ce2a7 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -2,7 +2,9 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Connection, IsNull, MoreThan, Not, Repository } from 'typeorm'; import { ArtImage } from '../artImage/entities/artImage.entity'; +import { Engage } from '../engage/entities/engage.entity'; import { Art } from './entities/art.entity'; +import { LikeArt } from './entities/likeArt.entity'; @Injectable() export class ArtService { @@ -174,4 +176,66 @@ export class ArtService { await queryRunner.manager.release(); } } + /////////////////////////////////////////////////////////////////////////// + async countEngage(userId) { + const queryRunner = this.connection.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + try { + const result = await queryRunner.manager.count(Engage, { + userId: userId, + }); + + await queryRunner.commitTransaction(); + return result; + } catch (error) { + await queryRunner.rollbackTransaction(); + throw error + 'Art create !'; + } finally { + await queryRunner.manager.release(); + } + } + + async countLikeArt(userId) { + const queryRunner = this.connection.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + try { + const result = await queryRunner.manager.count(LikeArt, { + userId: userId, + }); + + await queryRunner.commitTransaction(); + return result; + } catch (error) { + await queryRunner.rollbackTransaction(); + throw error + 'Art create !'; + } finally { + await queryRunner.manager.release(); + } + } + + async countComletedAuctionArts(userId) { + const result = await this.artRepository.count({ + withDeleted: true, + where: { user: userId, is_soldout: true }, + }); + return result; + } + + async countTimedoutArts(userId) { + const result = await this.artRepository.count({ + withDeleted: true, + where: { user: userId, deletedAt: Not(IsNull()) }, + }); + return result; + } + + async countAuctionArts(userId) { + const result = await this.artRepository.find({ + where: { user: userId, is_soldout: false }, + }); + return result; + } + /////////////////////////////////////////////////////////////////////////// } diff --git a/ars/src/apis/auth/auth.service.ts b/ars/src/apis/auth/auth.service.ts index 1d98209..270afbe 100644 --- a/ars/src/apis/auth/auth.service.ts +++ b/ars/src/apis/auth/auth.service.ts @@ -34,7 +34,6 @@ export class AuthService { if (!user) { const { password, ...rest } = req.user; - console.log(password, '비밀번호'); const hashedPassword = await bcrypt.hash(String(password), 1); const createUser = { ...rest, password: hashedPassword }; user = await this.userService.create({ ...createUser }); diff --git a/ars/src/apis/history/history.resolver.ts b/ars/src/apis/history/history.resolver.ts index c470aa2..1c47ec6 100644 --- a/ars/src/apis/history/history.resolver.ts +++ b/ars/src/apis/history/history.resolver.ts @@ -17,4 +17,10 @@ export class HistoryResolver { ) { return await this.historyService.findAll(currentUser.id, page); } + + @UseGuards(GqlAuthAccessGuard) + @Query(() => Number) + async fetchHitoryCount(@CurrentUser() currentUser: ICurrentUser) { + return await this.historyService.count(currentUser.id); + } } diff --git a/ars/src/apis/history/history.service.ts b/ars/src/apis/history/history.service.ts index acdaf77..2a52a4b 100644 --- a/ars/src/apis/history/history.service.ts +++ b/ars/src/apis/history/history.service.ts @@ -15,6 +15,11 @@ export class HistorySerive { take: 10, skip: 10 * (page - 1), where: { user: userId }, + order: { createdAt: 'ASC' }, }); } + + async count(userId) { + return await this.historyRepository.count({ user: userId }); + } } diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 96c5d4a..6acbc0e 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -122,12 +122,17 @@ type Query { fetchArts(tags: [String!]!, createdAt: String = "1970-2-10"): [Art!]! fetchArt(artId: String!): Art! fetchArtImages(artId: String!): [ArtImage!]! + fetchEngageCount: Float! + fetchLikeArtCount: Float! + fetchSoldoutArtsCount: Float! + fetchTimedOutArtsCount: Float! + fetchAuctionArtsCount: Float! fetchAuctionArts(page: Float!): [Art!]! fetchTimedOutArt(page: Float!): [Art!]! fetchTransactionCompletedArts(page: Float!): [Art!]! fetchEngaging(page: Float!): [Engage!]! - fetchArtistWorks(page: Float!, artId: String!): [Art!]! - fetchLikeArt: [Art!]! + fetchArtistWorks(artId: String!): [Art!]! + fetchLikeArt(page: Float!): [Art!]! fetchBoard(boardId: String!): Board! fetchBoardImgaes(boardId: String!): [BoardImage!]! fetchBoards: [Board!]! @@ -136,6 +141,7 @@ type Query { fetchLikeBoard: [Board!]! fetchComments(boardId: String!): [Comment!]! fetchHistory(page: Float!): [History!]! + fetchHitoryCount: Float! fetchProfile: Profile! fetchArtistProfile(artId: String!): Profile! fetchUser: User!