From 53705e6032aeb040988fb18f1d5974f4d36579c0 Mon Sep 17 00:00:00 2001 From: Arios67 Date: Sat, 2 Apr 2022 22:45:19 +0900 Subject: [PATCH] =?UTF-8?q?[#120]feat:=20=EC=B0=9C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/docker-compose.dev.yaml | 5 +- ars/docker-compose.yaml | 2 +- ars/src/apis/art/entities/likeArt.entity.ts | 5 +- ars/src/apis/auth/auth.service.ts | 9 +--- ars/src/apis/board/board.service.ts | 6 ++- ars/src/apis/likeArt/likeArt.service.ts | 59 +++++++++++++++------ ars/src/apis/payment/payment.service.ts | 6 +-- ars/src/app.module.ts | 2 + 8 files changed, 62 insertions(+), 32 deletions(-) diff --git a/ars/docker-compose.dev.yaml b/ars/docker-compose.dev.yaml index cd67f2a..d71fefb 100644 --- a/ars/docker-compose.dev.yaml +++ b/ars/docker-compose.dev.yaml @@ -2,14 +2,17 @@ version: '3.3' services: my_backend: + platform: linux/x86_64 + image: asia.gcr.io/artiful-a1/my_backend:2.0 build: context: . dockerfile: Dockerfile + env_file: + - ./.env.dev ports: - 3000:3000 volumes: - ./src:/myfolder/src - - ./.env:/myfolder/.env my_database: platform: linux/x86_64 diff --git a/ars/docker-compose.yaml b/ars/docker-compose.yaml index cd67f2a..02c4856 100644 --- a/ars/docker-compose.yaml +++ b/ars/docker-compose.yaml @@ -24,7 +24,7 @@ services: cap_add: - SYS_NICE ports: - - 3307:3306 + - 3306:3306 my_redis: image: redis:6.2.6 diff --git a/ars/src/apis/art/entities/likeArt.entity.ts b/ars/src/apis/art/entities/likeArt.entity.ts index ef20c3c..33ffe8d 100644 --- a/ars/src/apis/art/entities/likeArt.entity.ts +++ b/ars/src/apis/art/entities/likeArt.entity.ts @@ -1,4 +1,4 @@ -import { ObjectType } from '@nestjs/graphql'; +import { Field, ObjectType } from '@nestjs/graphql'; import { User } from 'src/apis/user/entities/user.entity'; import { Column, @@ -13,11 +13,12 @@ import { Art } from './art.entity'; @ObjectType() export class LikeArt { @PrimaryGeneratedColumn() + @Field(() => String) id: string; @Column() userId: string; - @ManyToOne(() => Art, { eager: true }) + @ManyToOne(() => Art) art: Art; } diff --git a/ars/src/apis/auth/auth.service.ts b/ars/src/apis/auth/auth.service.ts index c4026a9..44e3d73 100644 --- a/ars/src/apis/auth/auth.service.ts +++ b/ars/src/apis/auth/auth.service.ts @@ -31,23 +31,18 @@ export class AuthService { async loginOAuth(req, res) { let email = req.user.email; - console.log(email + '****************!!'); let user = await this.userService.findOne(email); - console.log('LLLLLLOOOOOO !' + user); - if (!user) { + + if (!user || !user.phoneNum) { const { password, ...rest } = req.user; const hashedPassword = await bcrypt.hash(String(password), 1); const createUser = { ...rest, password: hashedPassword }; user = await this.userService.create({ ...createUser }); this.setRefreshToken({ user, res }); - console.log('user created !!!'); res.redirect('https://artipul.shop/socialLogin'); - return user; } else { this.setRefreshToken({ user, res }); res.redirect('https://artipul.shop/'); - res.send(user); - return user; } } } diff --git a/ars/src/apis/board/board.service.ts b/ars/src/apis/board/board.service.ts index 9dd17b1..68b281c 100644 --- a/ars/src/apis/board/board.service.ts +++ b/ars/src/apis/board/board.service.ts @@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Connection, Repository } from 'typeorm'; import { BoardImage } from '../boardImage/entities/boardImage.entity'; import { Comment } from '../comment/entities/comment.entity'; +import { User } from '../user/entities/user.entity'; import { Board } from './entities/board.entity'; @Injectable() @@ -56,9 +57,12 @@ export class BoardService { await queryRunner.connect(); await queryRunner.startTransaction(); try { + const user = await queryRunner.manager.findOne(User, { + id: currentUser.id, + }); const result = await queryRunner.manager.save(Board, { ...rest, - user: currentUser, + user: user, thumbnail: image_urls[0], }); diff --git a/ars/src/apis/likeArt/likeArt.service.ts b/ars/src/apis/likeArt/likeArt.service.ts index 32e8894..4a2cd02 100644 --- a/ars/src/apis/likeArt/likeArt.service.ts +++ b/ars/src/apis/likeArt/likeArt.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; +import { Connection, Like, Repository } from 'typeorm'; +import { Art } from '../art/entities/art.entity'; import { LikeArt } from '../art/entities/likeArt.entity'; @Injectable() @@ -8,42 +9,66 @@ export class LikeArtService { constructor( @InjectRepository(LikeArt) private readonly likeArtRepository: Repository, + + private readonly connection: Connection, ) {} async find(userId, page) { - let arts = []; - if (page) { - arts = await this.likeArtRepository.find({ - take: 10, - skip: 10 * (page - 1), - where: { userId: userId }, - }); - } else { - arts = await this.likeArtRepository.find({ userId }); + const queryRunner = this.connection.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + try { + let arts = []; + if (page) { + arts = await queryRunner.manager.find(Art, { + take: 10, + skip: 10 * (page - 1), + where: { userId: userId }, + }); + } else { + arts = await queryRunner.manager.find(LikeArt, { + where: { userId }, + relations: ['art'], + }); + } + return arts.map((ele) => ele.art); + } catch (error) { + await queryRunner.rollbackTransaction(); + throw error + 'like art!!!'; + } finally { + await queryRunner.release(); } - - return arts.map((ele) => ele.art); } async like(artId, userId) { + const queryRunner = this.connection.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); try { - const prevLike = await this.likeArtRepository.findOne({ + const art = await queryRunner.manager.findOne(Art, { id: artId }); + const prevLike = await queryRunner.manager.findOne(LikeArt, { where: { userId: userId, art: artId, }, }); if (!prevLike) { - await this.likeArtRepository.save({ + await queryRunner.manager.save(LikeArt, { userId: userId, - art: artId, + art: art, }); + await queryRunner.commitTransaction(); + return true; } else { - await this.likeArtRepository.delete({ art: artId }); + await queryRunner.manager.delete(LikeArt, { art: artId }); + await queryRunner.commitTransaction(); + return false; } - return true; } catch (error) { + await queryRunner.rollbackTransaction(); throw error + 'like art!!!'; + } finally { + await queryRunner.release(); } } } diff --git a/ars/src/apis/payment/payment.service.ts b/ars/src/apis/payment/payment.service.ts index 4da015a..ac68135 100644 --- a/ars/src/apis/payment/payment.service.ts +++ b/ars/src/apis/payment/payment.service.ts @@ -64,7 +64,7 @@ export class PaymentService { }); // 유저 누적 포인트 업데이트 - const updated = await queryRunner.manager.save(User, { + const updatedUser = await queryRunner.manager.save(User, { ...bidder, point: bidder.point - price, }); @@ -72,8 +72,8 @@ export class PaymentService { // 히스토리 테이블(낙찰자) 저장 await queryRunner.manager.save(History, { point: price, - balance: updated.point, - user: updated, + balance: updatedUser.point, + user: updatedUser, payment: payment, }); diff --git a/ars/src/app.module.ts b/ars/src/app.module.ts index 3affd5c..2d5ec4b 100644 --- a/ars/src/app.module.ts +++ b/ars/src/app.module.ts @@ -15,6 +15,7 @@ import { ProfileModule } from './apis/profile/profile.module'; import { HistoryModule } from './apis/history/history.module'; import { ScheduleModule } from '@nestjs/schedule'; import { PaymentModule } from './apis/payment/payment.module'; +import { setgroups } from 'process'; @Module({ imports: [ @@ -47,6 +48,7 @@ import { PaymentModule } from './apis/payment/payment.module'; entities: [__dirname + '/apis/**/*.entity.*'], synchronize: true, logging: true, + timezone: 'Asia/seoul', }), CacheModule.register({ store: redisStore,