Skip to content

Commit

Permalink
Merge pull request #132 from Arios67/feat/#131
Browse files Browse the repository at this point in the history
feat/#131
  • Loading branch information
Arios67 committed Apr 3, 2022
2 parents edee8fb + 88ffe32 commit bfe42a2
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
35 changes: 13 additions & 22 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,24 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul00',
from: 0,
size: 500,
index: 'artipul09',
query: {
bool: {
must: [{ match: { tag1: tags[0] } }],
},
},
});

if (!result.hits.hits.length) return [];
if (!result.hits.hits.length) return null;

const artTags = result.hits.hits.map((el: any) => {
return {
id: el._source.id,
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,
Expand All @@ -80,26 +78,24 @@ 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] } }],
},
},
});

if (!result.hits.hits.length) return [];
if (!result.hits.hits.length) return null;

const artTags = result.hits.hits.map((el: any) => {
return {
id: el._source.id,
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,
Expand All @@ -121,9 +117,7 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul00',
from: 0,
size: 500,
index: 'artipul09',
query: {
bool: {
must: [
Expand All @@ -135,16 +129,16 @@ 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 {
id: el._source.id,
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,
Expand All @@ -167,9 +161,7 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul00',
from: 0,
size: 500,
index: 'artipul09',
query: {
bool: {
must: [
Expand All @@ -182,16 +174,16 @@ 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 {
id: el._source.id,
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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion ars/src/apis/board/board.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

// 게시물 수정
Expand Down
7 changes: 6 additions & 1 deletion ars/src/apis/board/board.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 { BoardImage } from '../boardImage/entities/boardImage.entity';
import { Comment } from '../comment/entities/comment.entity';
import { User } from '../user/entities/user.entity';
Expand Down Expand Up @@ -52,18 +53,22 @@ 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();
try {
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],
});

Expand Down
1 change: 1 addition & 0 deletions ars/src/apis/board/dto/createBoardInput.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, InputType } from '@nestjs/graphql';
import { Art } from 'src/apis/art/entities/art.entity';

@InputType()
export class CreateBoardInput {
Expand Down
6 changes: 6 additions & 0 deletions ars/src/apis/board/entities/board.entity.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -34,4 +36,8 @@ export class Board {
@ManyToOne(() => User, { eager: true })
@Field(() => User)
user: User;

@OneToOne(() => Art, { eager: true })
@Field(() => Art)
art: Art;
}
2 changes: 1 addition & 1 deletion ars/src/apis/event/event.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: /./,
})
Expand Down
3 changes: 2 additions & 1 deletion ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Board {
content: String!
thumbnail: String!
user: User!
art: Art!
}

type BoardImage {
Expand Down Expand Up @@ -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!]!
Expand Down

0 comments on commit bfe42a2

Please sign in to comment.