Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: time->hour로 파라미터 변경 작업 및 응답에서 course.userId가 누락되어 있던 문제 수정 #111

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/src/common/type/raw-recruit-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface RawRecruitData {
course_pathLength: number;
course_name: string;
course_createdAt: Date;
course_userId: string;
id: number;
title: string;
startTime: Date;
Expand Down
2 changes: 2 additions & 0 deletions server/src/common/utils/plainToGetRecruitDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const plainToGetRecruitDto = (plainRecruitData: RawRecruitData) => {
course_pathLength,
course_name,
course_createdAt,
course_userId,
} = plainRecruitData;

return {
Expand All @@ -34,6 +35,7 @@ export const plainToGetRecruitDto = (plainRecruitData: RawRecruitData) => {
img: course_img,
path: course_path,
pathLength: course_pathLength,
userId: course_userId,
hDong: {
name: course_name,
},
Expand Down
6 changes: 3 additions & 3 deletions server/src/recruit/dto/get-recruit.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class GetRecruitDto {
@IsOptional()
@Type(() => Number)
@IsNumber()
private time?: number;
private hour?: number;

@IsOptional()
@Type(() => Number)
Expand Down Expand Up @@ -66,8 +66,8 @@ export class GetRecruitDto {
return this.query;
}

getTime(): number | undefined {
return this.time;
getHour(): number | undefined {
return this.hour;
}

getDist(): number | undefined {
Expand Down
18 changes: 2 additions & 16 deletions server/src/recruit/recruit.controller.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import {
Body,
Controller,
Get,
Post,
UseGuards,
Query,
Param,
Req,
HttpException,
BadRequestException,
} from "@nestjs/common";
import { Body, Controller, Get, Post, Query, Param, Req } from "@nestjs/common";
import { JwtService } from "@nestjs/jwt";
import { AccessGuard } from "src/common/guard/access.guard";
import { CreateRecruitDto } from "./dto/create-recruit.dto";
import { GetRecruitDto } from "./dto/get-recruit.dto";
import { JoinRecruitDto } from "./dto/join-recruit.dto";
import { RecruitService } from "./recruit.service";
import { Request } from "express";

@Controller("recruit")
export class RecruitController {
Expand Down Expand Up @@ -45,7 +34,6 @@ export class RecruitController {
// @UseGuards(AccessGuard)
@Post("join")
async register(@Body() joinRecruitDto: JoinRecruitDto) {
console.log(joinRecruitDto);
const recruitId = joinRecruitDto.getRecruitId();
const userId = joinRecruitDto.getUserId();
if (!(await this.recruitService.isExistRecruit(recruitId))) {
Expand Down Expand Up @@ -85,11 +73,9 @@ export class RecruitController {

@Get(":id")
async getRecruitDetail(@Param("id") recruitId: number, @Req() request: Request) {
console.log("a");
const jwtString = request.headers["authorization"].split("Bearer")[1].trim();
const { userIdx } = this.jwtService.verify(jwtString, { secret: process.env.ACCESS_SECRET });
const data = await this.recruitService.getRecruitDetail(recruitId);
// return 1;
return {
...data,
isAuthor: data.authorId === userIdx,
Expand Down
9 changes: 6 additions & 3 deletions server/src/recruit/recruit.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class RecruitRepository extends Repository<Recruit> {
async createOne(recruitEntity: Recruit): Promise<Recruit> {
return this.save(recruitEntity);
}

async findRecruitDetail(recruitId: number) {
await this.findOneById(recruitId);
return this.createQueryBuilder("recruit")
Expand All @@ -17,7 +18,7 @@ export class RecruitRepository extends Repository<Recruit> {
.innerJoinAndSelect("recruit.user", "user")
.select([
"recruit.title AS title",
"recruit.startTime AS startTime",
"STR_TO_DATE(recruit.startTime) AS startTime",
"recruit.name AS name",
"recruit.maxPpl AS maxPpl",
"recruit.pace AS pace",
Expand All @@ -38,16 +39,17 @@ export class RecruitRepository extends Repository<Recruit> {
query?: string | undefined,
title?: boolean | undefined,
author?: boolean | undefined,
time?: number | undefined,
hour?: number | undefined,
minLen?: number | undefined,
maxLen?: number | undefined,
): Promise<RawRecruitData[]> {
return this.createQueryBuilder("recruit")
.innerJoinAndSelect("recruit.course", "course")
.innerJoinAndSelect("course.user", "u")
.leftJoinAndSelect("recruit.userRecruits", "user_recruit")
.innerJoinAndSelect("recruit.user", "user")
.where("recruit.startTime > NOW()")
.andWhere(time ? `recruit.startTime < DATE_ADD(NOW(), INTERVAL :time HOUR)` : "1=1", { time })
.andWhere(hour ? `recruit.startTime < DATE_ADD(NOW(), INTERVAL :hour HOUR)` : "1=1", { hour })
.andWhere(maxLen && minLen >= 0 ? `course.pathLength >= :minLen and course.pathLength < :maxLen` : "1=1", {
minLen,
maxLen,
Expand Down Expand Up @@ -79,6 +81,7 @@ export class RecruitRepository extends Repository<Recruit> {
"course.hCode",
"course.name",
"course.createdAt",
"u.userId AS course_userId",
])
.groupBy("recruit.id")
.offset((page - 1) * pageSize)
Expand Down
2 changes: 1 addition & 1 deletion server/src/recruit/recruit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class RecruitService {
queryParams.getQuery(),
queryParams.getTitle(),
queryParams.getAuthor(),
queryParams.getTime(),
queryParams.getHour(),
queryParams.getMinLength(),
queryParams.getMaxLength(),
);
Expand Down