Skip to content

Commit

Permalink
[#83]feat: 작품ID로 작가(프로필) 검색 api
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Mar 30, 2022
1 parent f122662 commit 1b0d294
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ars/src/apis/auth/auth.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class AuthResolver {
@Args('password') password: string,
@Context() context: any,
) {
const user = await this.userService.findOAuthUser({ email });
const user = await this.userService.findOne(email);
if (!user)
// 이메일 체크
throw new UnprocessableEntityException();
Expand Down
1 change: 0 additions & 1 deletion ars/src/apis/payment/payment.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export class PaymentResolver {
@Args('artId') artId: string,
@CurrentUser() currentUser: ICurrentUser,
) {
console.log(currentUser.id);
await this.paymentService.save(artId, currentUser.id);
return 'ok';
}
Expand Down
5 changes: 5 additions & 0 deletions ars/src/apis/profile/profile.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export class ProfileResolver {
return await this.profileService.findOne(currentUser.id);
}

@Query(() => Profile)
async fetchArtistProfile(@Args('artId') artId: string) {
return await this.profileService.findArtistFromArt(artId);
}

@UseGuards(GqlAuthAccessGuard)
@Mutation(() => Profile)
async createProfile(
Expand Down
20 changes: 20 additions & 0 deletions ars/src/apis/profile/profile.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, Repository } from 'typeorm';
import { Art } from '../art/entities/art.entity';
import { User } from '../user/entities/user.entity';
import { Profile } from './entities/profile.entity';

Expand All @@ -17,6 +18,25 @@ export class ProfileService {
return await this.profileRepository.findOne({ user: userId });
}

async findArtistFromArt(artId) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const art = await queryRunner.manager.findOne(Art, { id: artId });
const profile = await queryRunner.manager.findOne(Profile, {
user: art.user,
});
await queryRunner.commitTransaction();
return profile;
} catch (error) {
await queryRunner.rollbackTransaction();
throw error + 'findArtistFromArt !';
} finally {
await queryRunner.manager.release();
}
}

async create({ ...createProfileInput }, currentUser) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
Expand Down
4 changes: 0 additions & 4 deletions ars/src/apis/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export class UserService {
return await this.userRepository.findOne({ email });
}

async findOAuthUser({ email }) {
return await this.userRepository.findOne({ email });
}

async findUserEmail({ phoneNum }) {
const user = await this.userRepository.findOne({ phoneNum });
console.log(user.email);
Expand Down
1 change: 1 addition & 0 deletions ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type Query {
fetchComments(boardId: String!): [Comment!]!
fetchHistory(page: Float!): [History!]!
fetchProfile: Profile!
fetchArtistProfile(artId: String!): Profile!
fetchUser: User!
findUserEmail(phoneNum: String!): String!
fetchPurchaseList: Payment!
Expand Down

0 comments on commit 1b0d294

Please sign in to comment.