Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
chore: lint를 수행하라
Browse files Browse the repository at this point in the history
  • Loading branch information
kaaang committed Feb 18, 2024
1 parent d957410 commit 0627ed3
Show file tree
Hide file tree
Showing 86 changed files with 2,410 additions and 1,990 deletions.
1 change: 0 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {}
110 changes: 73 additions & 37 deletions src/comment/comment.controller.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,115 @@
import {Controller, Post, Body, Req, UseGuards, Param, Patch, Delete} from '@nestjs/common';
import {
Controller,
Post,
Body,
Req,
UseGuards,
Param,
Patch,
Delete,
} from '@nestjs/common';
import { CommentService } from './comment.service';
import { CreateCommentDto } from './dto/create-comment.dto';
import { ResponseCode } from '../response/response-code.enum';
import { ResponseDto } from '../response/response.dto';
import { UserGuard } from '../user/user.guard';
import { Request } from 'express';
import {UserEntity} from "../user/user.entity";
import {RuleMainEntity} from "../rule/domain/rule.main.entity";

@Controller('mate/rule/detail/comment')
export class CommentController {
constructor(
private readonly commentService: CommentService,
) {}
constructor(private readonly commentService: CommentService) {}

// [1] 댓글 작성
@Post('/:ruleId')
@UseGuards(UserGuard)
async createComment(@Body() dto: CreateCommentDto, @Param('ruleId') ruleId: number, @Req() req: Request): Promise<ResponseDto<any>> {
const result = await this.commentService.createComment(dto, ruleId, req.user.id);
async createComment(
@Body() dto: CreateCommentDto,
@Param('ruleId') ruleId: number,
@Req() req: Request,
): Promise<ResponseDto<any>> {
const result = await this.commentService.createComment(
dto,
ruleId,
req.user.id,
);

console.log('controller 진입')
if(!result){
console.log('controller 진입');
if (!result) {
return new ResponseDto(
ResponseCode.COMMENT_CREATION_FAIL,
false,
"여행 규칙 코멘트 생성 실패",
null);
}
else{
'여행 규칙 코멘트 생성 실패',
null,
);
} else {
return new ResponseDto(
ResponseCode.COMMENT_CREATED,
true,
"여행 규칙 코멘트 생성 성공",
result);
'여행 규칙 코멘트 생성 성공',
result,
);
}
}

// [2] 댓글 수정
@Patch('/:ruleId/:commentId')
@UseGuards(UserGuard)
async updateComment(@Body() dto: CreateCommentDto, @Param('ruleId') ruleId: number, @Param('commentId') commentId: number,@Req() req: Request): Promise<ResponseDto<any>> {
async updateComment(
@Body() dto: CreateCommentDto,
@Param('ruleId') ruleId: number,
@Param('commentId') commentId: number,
@Req() req: Request,
): Promise<ResponseDto<any>> {
try {
const result = await this.commentService.updateComment(dto, ruleId, req.user.id, commentId);
const result = await this.commentService.updateComment(
dto,
ruleId,
req.user.id,
commentId,
);
return new ResponseDto(
ResponseCode.COMMENT_UPDATE_SUCCESS,
true,
"여행 규칙 코멘트 수정 성공",
result);
ResponseCode.COMMENT_UPDATE_SUCCESS,
true,
'여행 규칙 코멘트 수정 성공',
result,
);
} catch (e) {
return new ResponseDto(
ResponseCode.COMMENT_UPDATE_FAIL,
false,
e.message,
null);
ResponseCode.COMMENT_UPDATE_FAIL,
false,
e.message,
null,
);
}
}

// [3] 댓글 삭제
@Delete('/:ruleId/:commentId')
@UseGuards(UserGuard)
async deleteComment(@Param('ruleId') ruleId: number, @Param('commentId') commentId: number,@Req() req: Request): Promise<ResponseDto<any>> {
async deleteComment(
@Param('ruleId') ruleId: number,
@Param('commentId') commentId: number,
@Req() req: Request,
): Promise<ResponseDto<any>> {
try {
const result = await this.commentService.deleteComment(ruleId, req.user.id, commentId);
const result = await this.commentService.deleteComment(
ruleId,
req.user.id,
commentId,
);
return new ResponseDto(
ResponseCode.COMMENT_DELETE_SUCCESS,
true,
"여행 규칙 코멘트 삭제 성공",
result);
ResponseCode.COMMENT_DELETE_SUCCESS,
true,
'여행 규칙 코멘트 삭제 성공',
result,
);
} catch (e) {
return new ResponseDto(
ResponseCode.COMMENT_DELETE_FAIL,
false,
e.message,
null);
ResponseCode.COMMENT_DELETE_FAIL,
false,
e.message,
null,
);
}
}
}
}
64 changes: 38 additions & 26 deletions src/comment/comment.service.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { CreateCommentDto } from './dto/create-comment.dto';
import { CommentEntity } from './domain/comment.entity';
import {RuleMainEntity} from "../rule/domain/rule.main.entity";
import {UserEntity} from "../user/user.entity";
import { RuleMainEntity } from '../rule/domain/rule.main.entity';
import { UserEntity } from '../user/user.entity';
import { NotificationEntity } from '../notification/notification.entity';
import { NotificationService } from '../notification/notification.service';

@Injectable()
export class CommentService {

// [1] 댓글 작성
async createComment(dto: CreateCommentDto, ruleId: number, userId: number): Promise<number> {

async createComment(
dto: CreateCommentDto,
ruleId: number,
userId: number,
): Promise<number> {
const comment = new CommentEntity();

const user = await UserEntity.findOneOrFail({ where: { id: userId } });
const rule = await RuleMainEntity.findOneOrFail({ where: { id: ruleId }, relations: { invitations: { member: true } } });
const rule = await RuleMainEntity.findOneOrFail({
where: { id: ruleId },
relations: { invitations: { member: true } },
});

if(!user || !rule){
if (!user || !rule) {
throw new Error('Data not found');
}
else{
console.log("user name: "+ user.name);
} else {
console.log('user name: ' + user.name);
comment.user = user;
console.log("rule id: "+ rule.id);
console.log('rule id: ' + rule.id);
comment.rule = rule;
comment.content = dto.content;
await comment.save();
Expand All @@ -48,25 +51,30 @@ export class CommentService {
}

// [2] 댓글 수정
async updateComment(dto: CreateCommentDto, ruleId: number, userId: number, commentId: number) : Promise<number> {
async updateComment(
dto: CreateCommentDto,
ruleId: number,
userId: number,
commentId: number,
): Promise<number> {
try {
// 사용자, 규칙, 댓글 검증
const user = await UserEntity.findOne({
where: {id : userId},
where: { id: userId },
});
if (!user) throw new NotFoundException('사용자를 찾을 수 없습니다');
const rule = await RuleMainEntity.findOne({
where: {id: ruleId},
})
where: { id: ruleId },
});
if (!rule) throw new NotFoundException('존재하지 않는 규칙입니다');
const comment = await CommentEntity.findOne({
where: {id: commentId}
where: { id: commentId },
});
if (!comment) throw new NotFoundException('존재하지 않는 댓글 입니다');

const checkValidateUser = await CommentEntity.findOne({
where: {id: commentId, user: {id: userId}, rule: {id: ruleId}}}
)
where: { id: commentId, user: { id: userId }, rule: { id: ruleId } },
});
if (!!checkValidateUser) {
comment.content = dto.content;
await CommentEntity.save(comment);
Expand All @@ -81,26 +89,30 @@ export class CommentService {
}

// [3] 댓글 삭제
async deleteComment(ruleId: number, userId: number, commentId: number) : Promise<number> {
async deleteComment(
ruleId: number,
userId: number,
commentId: number,
): Promise<number> {
try {
// 사용자, 규칙, 댓글 검증
const user = await UserEntity.findOne({
where: {id : userId},
where: { id: userId },
});
if (!user) throw new NotFoundException('사용자를 찾을 수 없습니다');
const rule = await RuleMainEntity.findOne({
where: {id: ruleId},
})
where: { id: ruleId },
});
if (!rule) throw new NotFoundException('존재하지 않는 규칙입니다');
const comment = await CommentEntity.findOne({
where: {id: commentId}
where: { id: commentId },
});
if (!comment) throw new NotFoundException('존재하지 않는 댓글 입니다');

// 해당 규칙에, 해당 사용자가 작성한, 해당 댓글 ID를 가진 댓글이 있는지 검증
const checkValidateUser = await CommentEntity.findOne({
where: {id: commentId, user: {id: userId}, rule: {id: ruleId}}}
)
where: { id: commentId, user: { id: userId }, rule: { id: ruleId } },
});
if (!!checkValidateUser) {
await comment.softRemove();
console.log('댓글 삭제 성공');
Expand Down
12 changes: 6 additions & 6 deletions src/comment/domain/comment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
JoinColumn,
CreateDateColumn,
UpdateDateColumn,
DeleteDateColumn
DeleteDateColumn,
} from 'typeorm';
import { RuleMainEntity } from 'src/rule/domain/rule.main.entity';
import { UserEntity } from 'src/user/user.entity';
Expand All @@ -20,12 +20,12 @@ export class CommentEntity extends BaseEntity {
@Column({ type: 'varchar', length: 200 })
content: string;

@ManyToOne(() => RuleMainEntity, ruleMain => ruleMain.comments)
@JoinColumn({ name: 'rule_id'})
@ManyToOne(() => RuleMainEntity, (ruleMain) => ruleMain.comments)
@JoinColumn({ name: 'rule_id' })
rule: RuleMainEntity;

@ManyToOne(() => UserEntity, user => user.comments)
@JoinColumn({ name: 'user_id'})
@ManyToOne(() => UserEntity, (user) => user.comments)
@JoinColumn({ name: 'user_id' })
user: UserEntity;

@CreateDateColumn()
Expand All @@ -36,4 +36,4 @@ export class CommentEntity extends BaseEntity {

@DeleteDateColumn()
deleted: Date;
}
}
8 changes: 4 additions & 4 deletions src/comment/dto/create-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class CreateCommentDto {
@IsNotEmpty()
@IsString()
content: string;
}
@IsNotEmpty()
@IsString()
content: string;
}
5 changes: 1 addition & 4 deletions src/detail-schedule/detail-schedule.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
import { ApiOkResponse, ApiOperation } from '@nestjs/swagger';
import { Request } from 'express';
import { DetailScheduleService } from './detail-schedule.service';
import {
DetailContentDto,
DetailScheduleInfoDto,
} from './detail-schedule-info.dto';
import { DetailContentDto } from './detail-schedule-info.dto';
import { UserGuard } from 'src/user/user.guard';

@Controller('detail-schedule')
Expand Down
6 changes: 1 addition & 5 deletions src/detail-schedule/detail-schedule.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import {
CreateDateColumn,
DeleteDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { NotFoundException } from '@nestjs/common';
import { BaseResponse } from 'src/response/response.status';
import { ScheduleEntity } from '../schedule/schedule.entity';
import {
DetailContentDto,
DetailScheduleInfoDto,
} from './detail-schedule-info.dto';
import { DetailContentDto } from './detail-schedule-info.dto';

@Entity()
export class DetailScheduleEntity extends BaseEntity {
Expand Down
8 changes: 2 additions & 6 deletions src/detail-schedule/detail-schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export class DetailScheduleService {
async createDetailSchedule(scheduleId: number, content: DetailContentDto) {
const schedule = await ScheduleEntity.findExistSchedule(scheduleId);
console.log(schedule.id);
const detailSchedule = await DetailScheduleEntity.createDetailSchedule(
schedule,
content,
);
await DetailScheduleEntity.createDetailSchedule(schedule, content);
return response(BaseResponse.DETAIL_SCHEDULE_CREATED);
}

Expand Down Expand Up @@ -45,8 +42,7 @@ export class DetailScheduleService {
//세부일정 삭제하기
async deleteDetailSchedule(detailId: number) {
const detailSchedule = await DetailScheduleEntity.findExistDetail(detailId);
const deleteDetailSchedule =
await DetailScheduleEntity.deleteDetailSchedule(detailSchedule);
await DetailScheduleEntity.deleteDetailSchedule(detailSchedule);
return response(BaseResponse.DELETE_DETAIL_SCHEDULE_SUCCESS);
}
}
1 change: 0 additions & 1 deletion src/diary/models/diary.image.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
UpdateDateColumn,
} from 'typeorm';
import { DiaryEntity } from './diary.entity';
import { S3UtilService } from 'src/utils/S3.service';

@Entity()
export class DiaryImageEntity extends BaseEntity {
Expand Down
Loading

0 comments on commit 0627ed3

Please sign in to comment.