Skip to content

Commit

Permalink
fix: pin 양방향 관계 설정, test에 반영 #255
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Dec 2, 2024
1 parent cd4602e commit 6a4b872
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/src/course/entity/CoursePlace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CoursePlace extends BaseEntity {
@JoinColumn({ name: 'place_id' })
place: Promise<Place>;

@ManyToOne(() => Course, {
@ManyToOne(() => Course, (course) => course.pins, {
onDelete: 'CASCADE',
orphanedRowAction: 'delete',
})
Expand Down
4 changes: 2 additions & 2 deletions backend/src/map/MapRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MapRepository extends SoftDeleteRepository<Map, number> {

async findMapsWithPlace(page: number, pageSize: number) {
return await this.createQueryBuilder('map')
.leftJoinAndSelect('map.mapPlaces', 'mapPlace')
.leftJoinAndSelect('map.pins', 'mapPlace')
.leftJoinAndSelect('map.user', 'user')
.where('map.isPublic = :isPublic', { isPublic: true })
.andWhere('mapPlace.id IS NOT NULL')
Expand All @@ -57,7 +57,7 @@ export class MapRepository extends SoftDeleteRepository<Map, number> {

async countMapsWithPlace() {
return await this.createQueryBuilder('map')
.leftJoinAndSelect('map.mapPlaces', 'mapPlace')
.leftJoinAndSelect('map.pins', 'mapPlace')
.where('map.isPublic = :isPublic', { isPublic: true })
.andWhere('mapPlace.id IS NOT NULL')
.getCount();
Expand Down
8 changes: 3 additions & 5 deletions backend/test/course/course.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ describe('CourseService', () => {
),
);
const setPlacesOfCourseRequest = {
places: places.map((place, index) => ({
pins: places.map((place, index) => ({
placeId: place.id,
comment: `Comment ${index + 1}`,
})),
Expand All @@ -386,11 +386,9 @@ describe('CourseService', () => {
setPlacesOfCourseRequest,
);

expect(result.places).toHaveLength(
setPlacesOfCourseRequest.places.length,
);
expect(result.places).toHaveLength(setPlacesOfCourseRequest.pins.length);

setPlacesOfCourseRequest.places.forEach((expectedPlace, index) => {
setPlacesOfCourseRequest.pins.forEach((expectedPlace, index) => {
expect(result.places[index]).toMatchObject({
id: expectedPlace.placeId,
comment: expectedPlace.comment,
Expand Down
2 changes: 1 addition & 1 deletion backend/test/map/map.repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('MapRepository', () => {
const expectedMaps = mapEntities.slice(5, 10).map((map) => {
return {
...map,
mapPlaces: map.pins.map((place) => {
pins: map.pins.map((place) => {
return {
color: place.color,
createdAt: place.createdAt,
Expand Down

0 comments on commit 6a4b872

Please sign in to comment.