From 88ffe323eb71a2f47fa23905cf9da7828f6e3460 Mon Sep 17 00:00:00 2001 From: Arios67 Date: Mon, 4 Apr 2022 03:27:49 +0900 Subject: [PATCH] feat/#131 --- ars/src/apis/art/art.resolver.ts | 35 ++++++++------------- ars/src/apis/board/board.resolver.ts | 7 ++++- ars/src/apis/board/board.service.ts | 7 ++++- ars/src/apis/board/dto/createBoardInput.ts | 1 + ars/src/apis/board/entities/board.entity.ts | 6 ++++ ars/src/apis/event/event.gateway.ts | 2 +- ars/src/common/graphql/schema.gql | 3 +- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index 5e9621f..1d0ab90 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -40,9 +40,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul00', - from: 0, - size: 500, + index: 'artipul09', query: { bool: { must: [{ match: { tag1: tags[0] } }], @@ -50,7 +48,7 @@ export class ArtResolver { }, }); - if (!result.hits.hits.length) return []; + if (!result.hits.hits.length) return null; const artTags = result.hits.hits.map((el: any) => { return { @@ -58,8 +56,8 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, + price: el._source.price, deadline: el._source.deadline, - is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, nickname: el._source.nickname, @@ -80,9 +78,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul00', - from: 0, - size: 500, + index: 'artipul09', query: { bool: { must: [{ match: { tag1: tags[0] } }, { match: { tag2: tags[1] } }], @@ -90,7 +86,7 @@ export class ArtResolver { }, }); - if (!result.hits.hits.length) return []; + if (!result.hits.hits.length) return null; const artTags = result.hits.hits.map((el: any) => { return { @@ -98,8 +94,8 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, + price: el._source.price, deadline: el._source.deadline, - is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, tag2: el._source.tag2, @@ -121,9 +117,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul00', - from: 0, - size: 500, + index: 'artipul09', query: { bool: { must: [ @@ -135,7 +129,7 @@ export class ArtResolver { }, }); - if (!result.hits.hits.length) return []; + if (!result.hits.hits.length) return null; const artTags = result.hits.hits.map((el: any) => { return { @@ -143,8 +137,8 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, + price: el._source.price, deadline: el._source.deadline, - is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, tag2: el._source.tag2, @@ -167,9 +161,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul00', - from: 0, - size: 500, + index: 'artipul09', query: { bool: { must: [ @@ -182,7 +174,7 @@ export class ArtResolver { }, }); - if (!result.hits.hits.length) return []; + if (!result.hits.hits.length) return null; const artTags = result.hits.hits.map((el: any) => { return { @@ -190,8 +182,8 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, + price: el._source.price, deadline: el._source.deadline, - is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, tag2: el._source.tag2, @@ -275,7 +267,7 @@ export class ArtResolver { @UseGuards(GqlAuthAccessGuard) @Query(() => [Art]) async fetchTransactionCompletedArts( - @Args('page', { nullable: true }) page: number, + @Args('page') page: number, @CurrentUser() currentUser: ICurrentUser, ) { return await this.artService.findcompleteAuction({ currentUser }, page); @@ -317,7 +309,6 @@ 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/board/board.resolver.ts b/ars/src/apis/board/board.resolver.ts index df87fea..4527fa0 100644 --- a/ars/src/apis/board/board.resolver.ts +++ b/ars/src/apis/board/board.resolver.ts @@ -58,9 +58,14 @@ export class BoardResolver { @Mutation(() => Board) async createBoard( @Args('createBoardInput') createBoardInput: CreateBoardInput, + @Args('artId') artId: string, @CurrentUser() currentUser: ICurrentUser, ) { - return await this.boardService.create({ ...createBoardInput }, currentUser); + return await this.boardService.create( + { ...createBoardInput }, + artId, + currentUser, + ); } // 게시물 수정 diff --git a/ars/src/apis/board/board.service.ts b/ars/src/apis/board/board.service.ts index bfa038f..2d7432b 100644 --- a/ars/src/apis/board/board.service.ts +++ b/ars/src/apis/board/board.service.ts @@ -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 { BoardImage } from '../boardImage/entities/boardImage.entity'; import { Comment } from '../comment/entities/comment.entity'; import { User } from '../user/entities/user.entity'; @@ -52,7 +53,7 @@ export class BoardService { } // 게시물 등록 - async create({ image_urls, ...rest }, currentUser) { + async create({ image_urls, ...rest }, artId, currentUser) { const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); await queryRunner.startTransaction(); @@ -60,10 +61,14 @@ export class BoardService { const user = await queryRunner.manager.findOne(User, { id: currentUser.id, }); + const art = await queryRunner.manager.findOne(Art, { + id: artId, + }); const result = await queryRunner.manager.save(Board, { ...rest, user: user, + art: art, thumbnail: image_urls[0], }); diff --git a/ars/src/apis/board/dto/createBoardInput.ts b/ars/src/apis/board/dto/createBoardInput.ts index 6379b5e..9ff5b91 100644 --- a/ars/src/apis/board/dto/createBoardInput.ts +++ b/ars/src/apis/board/dto/createBoardInput.ts @@ -1,4 +1,5 @@ import { Field, InputType } from '@nestjs/graphql'; +import { Art } from 'src/apis/art/entities/art.entity'; @InputType() export class CreateBoardInput { diff --git a/ars/src/apis/board/entities/board.entity.ts b/ars/src/apis/board/entities/board.entity.ts index 5dd3333..63a43b6 100644 --- a/ars/src/apis/board/entities/board.entity.ts +++ b/ars/src/apis/board/entities/board.entity.ts @@ -1,10 +1,12 @@ import { Field, Int, ObjectType } from '@nestjs/graphql'; +import { Art } from 'src/apis/art/entities/art.entity'; import { User } from 'src/apis/user/entities/user.entity'; import { Column, CreateDateColumn, Entity, ManyToOne, + OneToOne, PrimaryGeneratedColumn, } from 'typeorm'; @@ -34,4 +36,8 @@ export class Board { @ManyToOne(() => User, { eager: true }) @Field(() => User) user: User; + + @OneToOne(() => Art, { eager: true }) + @Field(() => Art) + art: Art; } diff --git a/ars/src/apis/event/event.gateway.ts b/ars/src/apis/event/event.gateway.ts index 5137630..d967dd2 100644 --- a/ars/src/apis/event/event.gateway.ts +++ b/ars/src/apis/event/event.gateway.ts @@ -8,7 +8,7 @@ import { Server, Socket } from 'socket.io'; @WebSocketGateway({ cors: { - origin: ['http://localhost:3000', 'https://mybackend.arios67.shop'], + origin: ['http://localhost:3000', 'https://daseul.shop'], }, namespace: /./, }) diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index a389f3e..52fa3b8 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -119,6 +119,7 @@ type Board { content: String! thumbnail: String! user: User! + art: Art! } type BoardImage { @@ -175,7 +176,7 @@ type Mutation { login(email: String!, password: String!): Token! restoreAccessToken: Token! logout: String! - createBoard(createBoardInput: CreateBoardInput!): Board! + createBoard(createBoardInput: CreateBoardInput!, artId: String!): Board! updateBoard(boardId: String!, updateBoardInput: UpdateBoardInput!): Board! deleteBoard(boardId: String!): Boolean! uploadBoardImage(files: [Upload!]!): [String!]!