Skip to content

Commit 51eaf14

Browse files
fix: beforeInsert로 snowflakeId 생성
1 parent de07f30 commit 51eaf14

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

apps/backend/src/user/user.entity.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Column,
66
CreateDateColumn,
77
Index,
8+
BeforeInsert,
89
} from 'typeorm';
910
import { Snowflake } from '@theinternetfolks/snowflake';
1011

@@ -15,7 +16,7 @@ export class User {
1516

1617
@Column({ unique: true })
1718
@Index()
18-
snowflakeId: string = Snowflake.generate();
19+
snowflakeId: string;
1920

2021
@Column({ unique: true })
2122
providerId: string; // 네이버/카카오 ID
@@ -34,4 +35,9 @@ export class User {
3435

3536
@CreateDateColumn()
3637
createdAt: Date;
38+
39+
@BeforeInsert()
40+
generateSnowflakeId() {
41+
this.snowflakeId = Snowflake.generate();
42+
}
3743
}

apps/backend/src/workspace/workspace.entity.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
CreateDateColumn,
77
UpdateDateColumn,
88
OneToMany,
9+
Index,
10+
BeforeInsert,
911
} from 'typeorm';
1012
import { User } from '../user/user.entity';
1113
import { Snowflake } from '@theinternetfolks/snowflake';
@@ -19,7 +21,8 @@ export class Workspace {
1921
id: number;
2022

2123
@Column({ unique: true })
22-
snowflakeId: string = Snowflake.generate();
24+
@Index()
25+
snowflakeId: string;
2326

2427
@ManyToOne(() => User, { nullable: false })
2528
owner: User;
@@ -50,4 +53,9 @@ export class Workspace {
5053

5154
@OneToMany(() => Node, (node) => node.workspace)
5255
nodes: Node[];
56+
57+
@BeforeInsert()
58+
generateSnowflakeId() {
59+
this.snowflakeId = Snowflake.generate();
60+
}
5361
}

0 commit comments

Comments
 (0)