Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppController } from './app.controller';
import { AlarmsModule } from './alarms/alarms.module';
import { ScheduleModule } from './schedules/schedule.module';
import { UserModule } from './users/user.module';
import { CategoryModule } from './categories/category.module';

@Module({
imports: [
Expand All @@ -29,6 +30,7 @@ import { UserModule } from './users/user.module';
AlarmsModule,
ScheduleModule,
UserModule,
CategoryModule,
],
controllers: [AppController],
providers: [],
Expand Down
9 changes: 9 additions & 0 deletions src/categories/category.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CategoryEntity } from './entities/category.entity';

@Module({
imports: [TypeOrmModule.forFeature([CategoryEntity])],
exports: [TypeOrmModule],
})
export class CategoryModule {}
74 changes: 74 additions & 0 deletions src/categories/entities/category.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
BaseEntity,
Column,
CreateDateColumn,
DeleteDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';

export enum CategoryColor {
BLUE = 'BLUE',
BROWN = 'BROWN',
GREEN = 'GREEN',
PURPLE = 'PURPLE',
PINK = 'PINK',
}

@Entity('Category')
export class CategoryEntity extends BaseEntity {
@PrimaryGeneratedColumn({ name: 'category_id', type: 'int' })
categoryId: number;

@Column({
name: 'category_name',
type: 'varchar',
length: 30,
nullable: false,
comment: '카테고리명',
})
categoryName: string;

@Column({
name: 'category_color',
type: 'enum',
enum: CategoryColor,
enumName: 'category_color_enum',
nullable: false,
comment: '카테고리 색',
})
categoryColor: CategoryColor;

@Column({
name: 'user_id',
type: 'int',
nullable: false,
comment: '사용자 아이디',
})
userId: number;
Comment on lines +43 to +49

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

userId에 관계 매핑과 인덱스가 없습니다.

userId가 순수 컬럼으로만 정의되어 있어 User 엔티티와의 관계 매핑(@ManyToOne 등)이 없고, FK 참조 무결성이 DB 레벨에서 보장되지 않습니다. 또한 카테고리 목록 조회가 사용자 기준으로 자주 수행될 것으로 예상되는데 userId에 인덱스가 없어 조회 성능에 영향을 줄 수 있습니다.

As per path instructions, "관계 매핑과 cascade 설정이 안전한지" 및 "필요한 인덱스/유니크 제약이 누락되지 않았는지"를 확인해야 합니다.

🔧 관계 매핑 및 인덱스 추가 예시
-  `@Column`({
-    name: 'user_id',
-    type: 'int',
-    nullable: false,
-    comment: '사용자 아이디',
-  })
-  userId: number;
+  `@Index`()
+  `@Column`({
+    name: 'user_id',
+    type: 'int',
+    nullable: false,
+    comment: '사용자 아이디',
+  })
+  userId: number;
+
+  `@ManyToOne`(() => UserEntity)
+  `@JoinColumn`({ name: 'user_id' })
+  user: UserEntity;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Column({
name: 'user_id',
type: 'int',
nullable: false,
comment: '사용자 아이디',
})
userId: number;
`@Index`()
`@Column`({
name: 'user_id',
type: 'int',
nullable: false,
comment: '사용자 아이디',
})
userId: number;
`@ManyToOne`(() => UserEntity)
`@JoinColumn`({ name: 'user_id' })
user: UserEntity;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/categories/entities/category.entity.ts` around lines 43 - 49, Category
entity의 userId가 단순 컬럼으로만 선언되어 있어 User와의 관계 및 DB 레벨 FK 보장이 빠져 있습니다. Category
엔티티에서 userId를 User 엔티티와 연결하는 관계 매핑(`@ManyToOne` 등)을 추가하고, 필요한 경우 연결 컬럼 설정도 함께
정리하세요. 또한 카테고리 조회 성능을 위해 userId에 인덱스를 추가하고, 중복 방지가 필요하다면 Category 엔티티의 유니크 제약도
함께 검토해 반영하세요.

Source: Path instructions


@CreateDateColumn({
name: 'created_at',
type: 'timestamp',
nullable: false,
comment: '생성일',
})
createdAt: Date;

@UpdateDateColumn({
name: 'updated_at',
type: 'timestamp',
nullable: true,
comment: '수정일',
})
updatedAt: Date | null;

@DeleteDateColumn({
name: 'deleted_at',
type: 'timestamp',
nullable: true,
comment: '삭제일',
})
deletedAt: Date | null;
}