Skip to content

Commit

Permalink
[Fix] records 조회에서 workouts 이름이 누락되는 문제, 로그인시 엑세스 토큰을 받고, 리프래쉬 토큰을 받을…
Browse files Browse the repository at this point in the history
… 때, 타임아웃 이 걸리는 문제 (#314)

* fix: leftjoin 후, 운동 종류 name을 리턴하도록 수정

* fix: 엔티티 주석 제거

* chore: 커넥션 풀 사용

* fix: record 스웨거 수정

Co-authored-by: sjy982 <[email protected]>

---------

Co-authored-by: sjy982 <[email protected]>
  • Loading branch information
wonholim and sjy982 authored Dec 9, 2023
1 parent a22a7b5 commit 0281848
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions BackEnd/src/config/typeorm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export const typeOrmConfig: TypeOrmModuleOptions = {
synchronize: false,
logging: true,
charset: 'utf8mb4',
extra: {
connectionLimit: 10,
}
};
15 changes: 7 additions & 8 deletions BackEnd/src/records/dto/record-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApiProperty, PickType } from '@nestjs/swagger';
import { SuccessResDto } from '../../common/dto/SuccessRes.dto';
import { Record } from '../entities/records.entity';

import { Workout } from 'src/workouts/entities/workout.entity';
class WorkoutDto extends PickType(Workout, ['name']) {}
class GetRecord extends PickType(Record, [
'workout',
'profile',
'workoutTime',
'distance',
Expand All @@ -14,21 +14,20 @@ class GetRecord extends PickType(Record, [
'createdAt',
'mapCapture',
'gps'
]) {}

]) {
@ApiProperty( {type: () => WorkoutDto} )
workout: WorkoutDto;
}
class GetRecordWithId extends PickType(Record, ['id']) {}

export class CreateRecordResDto extends SuccessResDto {
@ApiProperty({ type: () => GetRecordWithId })
data: Pick<GetRecordWithId, 'id'>;
}

export class GetUsersRecordsResDto extends SuccessResDto {
@ApiProperty({ type: () => [GetRecord] })
data: GetRecord[];
}

export class GetRecordResDto extends SuccessResDto {
@ApiProperty({ type: () => GetRecord })
data: GetRecord;
}
}
2 changes: 1 addition & 1 deletion BackEnd/src/records/entities/records.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Record {
@Column({ default: false })
isPosted: boolean;

@ManyToOne(() => Profile, (profile) => profile.records) //manyToOne이 항상 외래키를 갖고 있음
@ManyToOne(() => Profile, (profile) => profile.records)
profile: Profile;

@OneToOne(() => Post, (post) => post.record)
Expand Down
15 changes: 9 additions & 6 deletions BackEnd/src/records/records.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class RecordsService {
findByDate(profileId: number, year: number, month: number, day: number) {
return this.recordsRepository
.createQueryBuilder('record')
.leftJoinAndSelect('record.workout', 'workout')
.leftJoin('record.workout', 'workout')
.addSelect('workout.name')
.where('record.profileId = :profileId', { profileId })
.andWhere(
`YEAR(record.createdAt) = :year AND MONTH(record.createdAt) = :month AND DAY(record.createdAt) = :day`,
Expand All @@ -40,11 +41,13 @@ export class RecordsService {
}

async findById(recordId: number) {
const result = await this.recordsRepository.findOne({
where: {
id: recordId,
},
});
const result = await this.recordsRepository
.createQueryBuilder('record')
.leftJoin('record.workout', 'workout')
.addSelect('workout.name')
.where('record.id = :recordId', { recordId })
.getOne();

if (!result) {
throw new NotFoundRecordException();
}
Expand Down

0 comments on commit 0281848

Please sign in to comment.