Skip to content

Commit

Permalink
Merge pull request #126 from Daseul1/feat/#122
Browse files Browse the repository at this point in the history
[#122]feat:좋아요 기능 수정
  • Loading branch information
Daseul1 committed Apr 3, 2022
2 parents 1697336 + 0ba4753 commit d3ee7bb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ars/src/apis/likeBoard/likeBoard.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, getRepository, Repository } from 'typeorm';
import { Connection, Repository } from 'typeorm';
import { Board } from '../board/entities/board.entity';
import { LikeBoard } from '../board/entities/likeBoard.entity';

@Injectable()
Expand Down Expand Up @@ -37,16 +38,19 @@ export class LikeBoardService {
await queryRunner.connect();
await queryRunner.startTransaction('SERIALIZABLE');
try {
const board = await queryRunner.manager.findOne(Board, { id: boardId });
const prevLike = await queryRunner.manager.findOne(LikeBoard, {
where: {
userId: userId,
board: boardId,
},
relations: ['board'],
lock: { mode: 'pessimistic_write' },
});
if (!prevLike) {
await queryRunner.manager.save(LikeBoard, {
userId: userId,
board: boardId,
board: board,
});
await queryRunner.commitTransaction();
return true;
Expand Down

0 comments on commit d3ee7bb

Please sign in to comment.