Skip to content

Commit

Permalink
Merge pull request #157 from modern-agile-team/feature/notice
Browse files Browse the repository at this point in the history
Feature/notice
  • Loading branch information
hobiJeong authored Dec 21, 2023
2 parents 42b98aa + f7b4d62 commit 87277f3
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 50 deletions.
8 changes: 3 additions & 5 deletions src/boards/controllers/Boards.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import { ApiDeleteBoard } from '../swagger-decorators/delete-board-decorators';
import { ApiUpdateBoardImage } from '../swagger-decorators/patch-board-images-decorators';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';
import { BoardOwnerGuard } from 'src/config/guards/board-owner.guard';
import { BoardOwner } from 'src/common/decorators/board-owner.decorator';
import { JwtOptionalGuard } from 'src/config/guards/jwt-optional.guard';

@Controller('boards')
@ApiTags('board API')
Expand Down Expand Up @@ -74,14 +73,13 @@ export class BoardsController {
}

@Get('/unit')
@UseGuards(BoardOwnerGuard)
@UseGuards(JwtOptionalGuard)
@ApiGetOneBoard()
async findOne(
@Query('boardId') boardId: number,
@BoardOwner() unitOnwer: boolean,
@GetUserId() userId: number,
): Promise<BoardResponseDTO> {
return await this.boardsService.findOneBoard(boardId, userId, unitOnwer);
return await this.boardsService.findOneBoard(boardId, userId);
}

@Patch('')
Expand Down
3 changes: 1 addition & 2 deletions src/boards/services/Boards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ export class BoardsService {
async findOneBoard(
boardId: number,
userId: number,
unitOnwer: boolean,
): Promise<oneBoardResponseDTO> {
const board = await this.boardRepository.findBoardById(boardId);
const unitowner = unitOnwer;
const unitowner = board.userId === userId;
if (!board) {
throw new Error('게시물을 찾을 수 없습니다.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/chat/controllers/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ApiGetChatNotificationSse } from '../swagger-decorators/get-chat-notifi
import { TokenService } from 'src/auth/services/token.service';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';
import { GetNotificationsResponseDto } from '../dto/get-notifications-response.dto';
import { GetNotificationsResponseFromChatDto } from '../dto/get-notifications-response-from-chat.dto';
import { ApiGetChatNotifications } from '../swagger-decorators/get-chat-notifications.decorator';
import { ApiCreateChatImage } from '../swagger-decorators/create-chat-image.decorators';
import { SuccessResponseInterceptor } from 'src/common/interceptors/success-response.interceptor';
Expand Down Expand Up @@ -119,7 +119,7 @@ export class ChatController {
@Get('chat/notice')
async getChatNotifications(
@GetUserId() userId: number,
): Promise<GetNotificationsResponseDto[]> {
): Promise<GetNotificationsResponseFromChatDto[]> {
return this.chatService.getChatNotifications(userId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';

export class GetNotificationsResponseDto {
export class GetNotificationsResponseFromChatDto {
_id: mongoose.Types.ObjectId;

chatroom_id: mongoose.Types.ObjectId;
Expand Down
4 changes: 2 additions & 2 deletions src/chat/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Subject, catchError, map } from 'rxjs';
import { Chat } from '../schemas/chat.schemas';
import { User } from 'src/users/entities/user.entity';
import { EntityManager } from 'typeorm';
import { GetNotificationsResponseDto } from '../dto/get-notifications-response.dto';
import { GetNotificationsResponseFromChatDto } from '../dto/get-notifications-response-from-chat.dto';

@Injectable()
export class ChatService {
Expand Down Expand Up @@ -202,7 +202,7 @@ export class ChatService {

async getChatNotifications(
userId: number,
): Promise<GetNotificationsResponseDto[]> {
): Promise<GetNotificationsResponseFromChatDto[]> {
const isUser = await this.entityManager.findOne(User, {
where: { id: userId },
});
Expand Down
3 changes: 2 additions & 1 deletion src/comments/controllers/comments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ApiAddReComment } from '../swagger-decoratros/add-recomment-decorators'
import { ApiUpdateReComment } from '../swagger-decoratros/patch-recomment-decorator';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';
import { JwtOptionalGuard } from 'src/config/guards/jwt-optional.guard';

@Controller('comments')
@ApiTags('Comment API')
Expand Down Expand Up @@ -60,7 +61,7 @@ export class CommentsController {
}

@Get('')
@UseGuards(JwtAccessTokenGuard)
@UseGuards(JwtOptionalGuard)
@ApiGetAllComment()
async getComment(
@GetUserId() userId: number,
Expand Down
7 changes: 7 additions & 0 deletions src/common/dto/get-notifications-response-from-board.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { OmitType } from '@nestjs/swagger';
import { BoardNotification } from '../notice/entities/board-notice.entity';

export class GetNotificationsResponseFromBoardDto extends OmitType(
BoardNotification,
['board', 'receiver', 'sender'],
) {}
14 changes: 11 additions & 3 deletions src/common/notice/controllers/notice.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import {
Controller,
Delete,
Get,
Headers,
Param,
ParseIntPipe,
Patch,
UseGuards,
UseInterceptors,
UsePipes,
ValidationPipe,
} from '@nestjs/common';
Expand All @@ -15,9 +16,14 @@ import { ApiTags } from '@nestjs/swagger';
import { ApiGetAllNotifications } from '../swagger-decorators/get-all-notifications.decorator';
import { ApiUpdateUnSeenNotification } from '../swagger-decorators/update-un-seen-notification.decorator';
import { ApiHardDeleteNotificatons } from '../swagger-decorators/hard-delete-notifications.decorator';
import { SuccessResponseInterceptor } from 'src/common/interceptors/success-response.interceptor';
import { GetNotificationsResponseFromBoardDto } from 'src/common/dto/get-notifications-response-from-board.dto';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';

@ApiTags('BOARD-NOTICE')
@UsePipes(ValidationPipe)
@UseInterceptors(SuccessResponseInterceptor)
@Controller('notice')
export class NoticeController {
constructor(
Expand All @@ -26,9 +32,11 @@ export class NoticeController {
) {}

@ApiGetAllNotifications()
@UseGuards(JwtAccessTokenGuard)
@Get()
async getAllNotifications(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
async getAllNotifications(
@GetUserId() userId: number,
): Promise<GetNotificationsResponseFromBoardDto[]> {
return this.noticeService.getAllNotifications(userId);
}

Expand Down
5 changes: 4 additions & 1 deletion src/common/notice/repositories/notice.repository.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { EntityManager, LessThan } from 'typeorm';
import { BoardNotification, Separator } from '../entities/board-notice.entity';
import { GetNotificationsResponseFromBoardDto } from 'src/common/dto/get-notifications-response-from-board.dto';

@Injectable()
export class NoticeRepository {
constructor(private entityManager: EntityManager) {}

async getAllNotifications(userId: number) {
async getAllNotifications(
userId: number,
): Promise<GetNotificationsResponseFromBoardDto[]> {
const notifications = await this.entityManager.find(BoardNotification, {
skip: 1,
take: 10,
Expand Down
20 changes: 16 additions & 4 deletions src/common/notice/services/notice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
import { NoticeRepository } from '../repositories/notice.repository';
import { EntityManager } from 'typeorm';
import { User } from 'src/users/entities/user.entity';
import { GetNotificationsResponseFromBoardDto } from 'src/common/dto/get-notifications-response-from-board.dto';

@Injectable()
export class NoticeService {
Expand All @@ -10,7 +11,9 @@ export class NoticeService {
private entityManager: EntityManager,
) {}

async getAllNotifications(userId: number) {
async getAllNotifications(
userId: number,
): Promise<GetNotificationsResponseFromBoardDto[]> {
const isUser = await this.entityManager.findOne(User, {
where: { id: userId },
});
Expand All @@ -24,7 +27,10 @@ export class NoticeService {
boardId: number,
senderId: number,
receiverId: number,
) {
): Promise<void | GetNotificationsResponseFromBoardDto> {
if (senderId === receiverId) {
return;
}
return this.noticeRepository.createBoardNoticeFromComment(
boardId,
senderId,
Expand All @@ -36,7 +42,10 @@ export class NoticeService {
boardId: number,
senderId: number,
receiverId: number,
) {
): Promise<void | GetNotificationsResponseFromBoardDto> {
if (senderId === receiverId) {
return;
}
return this.noticeRepository.createCommentNoticeFromReComment(
boardId,
senderId,
Expand All @@ -48,7 +57,10 @@ export class NoticeService {
boardId: number,
senderId: number,
receiverId: number,
) {
): Promise<void | GetNotificationsResponseFromBoardDto> {
if (senderId === receiverId) {
return;
}
return this.noticeRepository.createBoardNoticeFromLike(
boardId,
senderId,
Expand Down
29 changes: 0 additions & 29 deletions src/config/guards/board-owner.guard.ts

This file was deleted.

0 comments on commit 87277f3

Please sign in to comment.