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 ef19738..ee967ac 100644 --- a/ars/src/apis/art/entities/likeArt.entity.ts +++ b/ars/src/apis/art/entities/likeArt.entity.ts @@ -1,16 +1,25 @@ -import { ObjectType } from '@nestjs/graphql'; -import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; + +import { Field, ObjectType } from '@nestjs/graphql'; +import { User } from 'src/apis/user/entities/user.entity'; +import { + Column, + Entity, + ManyToOne, + PrimaryColumn, + PrimaryGeneratedColumn, +} from 'typeorm'; import { Art } from './art.entity'; @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 042275a..44e3d73 100644 --- a/ars/src/apis/auth/auth.service.ts +++ b/ars/src/apis/auth/auth.service.ts @@ -32,7 +32,8 @@ export class AuthService { async loginOAuth(req, res) { let email = req.user.email; let user = await this.userService.findOne(email); - if (!user) { + + if (!user || !user.phoneNum) { const { password, ...rest } = req.user; const hashedPassword = await bcrypt.hash(String(password), 1); const createUser = { ...rest, password: hashedPassword }; 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 21ad61a..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: [