-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject.model.ts
163 lines (144 loc) · 4 KB
/
project.model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { ObjectType, Field, ID } from '@nestjs/graphql';
import { SystemBaseModel } from 'src/system-base-model/system-base.model';
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
ManyToMany,
JoinTable,
OneToMany,
RelationId,
} from 'typeorm';
import { User } from 'src/user/user.model';
import { ProjectPackages } from './project-packages.model';
import { Chat } from 'src/chat/chat.model';
@Entity()
@ObjectType()
export class Project extends SystemBaseModel {
@Field(() => ID)
@PrimaryGeneratedColumn('uuid')
id: string;
@Field()
@Column()
projectName: string;
@Field()
@Column()
projectPath: string;
@Field(() => ID)
@RelationId((project: Project) => project.user)
@Column({ name: 'user_id' })
userId: string;
@ManyToOne(() => User, (user) => user.projects, {
onDelete: 'CASCADE',
nullable: false,
})
@JoinColumn({ name: 'user_id' })
@Field(() => User)
user: User;
@Field(() => [ProjectPackages], { nullable: true })
@ManyToMany(
() => ProjectPackages,
(projectPackage) => projectPackage.projects,
)
@JoinTable({
name: 'project_packages_mapping',
joinColumn: {
name: 'project_id',
referencedColumnName: 'id',
},
inverseJoinColumn: {
name: 'package_id',
referencedColumnName: 'id',
},
})
projectPackages: ProjectPackages[];
@Field(() => [Chat])
@OneToMany(() => Chat, (chat) => chat.project, {
cascade: true, // Automatically save related chats
lazy: true, // Load chats only when accessed
onDelete: 'CASCADE', // Delete chats when project is deleted
})
chats: Promise<Chat[]>;
/**
* Represents whether the project is public or private
*/
@Field()
@Column({ default: false })
isPublic: boolean;
/**
* Counts the number of times this project has been subscribed to (copied)
*/
@Field()
@Column({ default: 0 })
subNumber: number;
/**
* The URL to the project's screenshot or thumbnail
*/
@Field({ nullable: true })
@Column({ nullable: true })
photoUrl: string;
/**
* The name of the repo in GitHub (e.g. "my-cool-project").
*/
@Field({ nullable: true })
@Column({ nullable: true })
githubRepoName?: string;
/**
* The GitHub HTML URL for this repo (e.g. "https://github.com/username/my-cool-project").
*/
@Field({ nullable: true })
@Column({ nullable: true })
githubRepoUrl?: string;
/**
* The GitHub username or organization name that owns the repo.
*/
@Field({ nullable: true })
@Column({ nullable: true })
githubOwner?: string;
/**
* Whether this project has been synced/pushed to GitHub.
*/
@Field()
@Column({ default: false })
isSyncedWithGitHub: boolean;
/**
* Unique identifier for tracking project lineage
* Used to track which projects are copies of others
*/
@Field()
@Column({ unique: true, default: () => 'uuid_generate_v4()' })
uniqueProjectId: string;
/**
* If this project is a copy/fork, stores the uniqueProjectId of the original project.
* Projects with forkedFromId are fully editable by their new owner while maintaining
* a reference to the original project they were copied from.
*/
@Field({ nullable: true })
@Column({ nullable: true })
forkedFromId: string;
/**
* Reference to the original project if this is a copy/fork
*/
@Field(() => Project, { nullable: true })
@ManyToOne(() => Project, (project) => project.forks, { nullable: true })
@JoinColumn({ name: 'forkedFromId', referencedColumnName: 'uniqueProjectId' })
forkedFrom: Project;
/**
* Projects that were copied from this project
*/
@Field(() => [Project], { nullable: true })
@OneToMany(() => Project, (project) => project.forkedFrom)
forks: Project[];
/**
* Projects copied from this one
* Maintained for backwards compatibility, same as forks
*/
@Field(() => [Project], {
nullable: true,
description: 'Projects that are copies of this project',
})
@OneToMany(() => Project, (project) => project.forkedFrom)
subscribers: Project[];
}