Skip to content

Commit

Permalink
[#95]feat: mypage 요청개수 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Mar 31, 2022
1 parent 40e708a commit 0f87e3e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
31 changes: 31 additions & 0 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions ars/src/apis/art/art.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
///////////////////////////////////////////////////////////////////////////
}
1 change: 0 additions & 1 deletion ars/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
6 changes: 6 additions & 0 deletions ars/src/apis/history/history.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions ars/src/apis/history/history.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
10 changes: 8 additions & 2 deletions ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]!
Expand All @@ -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!
Expand Down

0 comments on commit 0f87e3e

Please sign in to comment.